Get the default values of table columns in Postgres?

前端 未结 6 1982
温柔的废话
温柔的废话 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:21

    you can just type " \d table_name" command , then It will displays some information about the table, such as the default value of a column.

    --create table

    skytf=> CREATE TABLE mytable (
    skytf(>     a integer DEFAULT 2,
    skytf(>     b varchar(64)  DEFAULT 'I am default',
    skytf(>     c varchar(64)  DEFAULT 'I am also default'
    skytf(> );
    CREATE TABLE
    

    --show table information

    skytf=> \d mytable
                                  Table "skytf.mytable"
     Column |         Type          |                   Modifiers                    
    --------+-----------------------+------------------------------------------------
     a      | integer               | default 2
     b      | character varying(64) | default 'I am default'::character varying
     c      | character varying(64) | default 'I am also default'::character varying
    

提交回复
热议问题