PostgreSQL View the table structure

前端之家收集整理的这篇文章主要介绍了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)
原文链接:https://www.f2er.com/postgresql/196112.html

猜你在找的Postgre SQL相关文章