PostgreSQL View the table structure

command line

testdb=> \dt
         List of relations
 Schema |   Name    | Type  | Owner 
--------+-----------+-------+-------
 public | orderinfo | table | zwc
(1 row)

testdb=> 
testdb=> \d orderinfo
                                    Table "public.orderinfo"
    Column    |     Type     |                            Modifiers                             
--------------+--------------+------------------------------------------------------------------
 orderinfo_id | integer      | not null default nextval('orderinfo_orderinfo_id_seq'::regclass)
 customer_id  | integer      | not null
 date_placed  | date         | not null
 date_shipped | date         | 
 shipping     | numeric(7,2) | 
Indexes:
    "orderinfo_pk" PRIMARY KEY, btree (orderinfo_id)


SQL

testdb=> SELECT
testdb-> A .attname AS field,
testdb-> T .typname AS TYPE,
testdb-> A .attlen AS LENGTH,
testdb-> A .attnotnull AS NOTNULL
testdb-> FROM
testdb-> pg_class C,
testdb-> pg_attribute A,
testdb-> pg_type T
testdb-> WHERE
testdb-> C .relname = 'orderinfo'
testdb-> AND A .attnum > 0
testdb-> AND A .attrelid = C .oid
testdb-> AND A .atttypid = T .oid;
    field     |  type   | length | notnull 
--------------+---------+--------+---------
 orderinfo_id | int4    |      4 | t
 customer_id  | int4    |      4 | t
 date_placed  | date    |      4 | t
 date_shipped | date    |      4 | f
 shipping     | numeric |     -1 | f
(5 rows)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值