Get the default values of table columns in Postgres?

前端 未结 6 2003
温柔的废话
温柔的废话 2020-11-29 11:21

I\'m looking for a way to run a query to find the default values of the columns of a table in Postgres. For example, if I made a table with the following query:

6条回答
  •  死守一世寂寞
    2020-11-29 11:48

     SELECT adsrc as default_value
     FROM pg_attrdef pad, pg_atttribute pat, pg_class pc
     WHERE pc.relname='your_table_name'
         AND pc.oid=pat.attrelid AND pat.attname='your_column_name'
         AND pat.attrelid=pad.adrelid AND pat.attnum=pad.adnum
    

    I found this query for postgresql on one of the blogs. you can try this to check if it works. To get values of all coumns, you can try removing AND pat.attname='your_column_name' from where clause.

提交回复
热议问题