2017-04-13 136 views
0

我已經遷移MySQL數據庫向PostgreSQL &替換查詢

SHOW FULL COLUMNS FROM schema_name.table_name;

有一個Postgres等同,

SELECT * FROM information_schema.columns WHERE table_schema = 'schema_name' and table_name = 'table_name';

返回列及其屬性一起然而這是在MySQL返回「評論」屬性查詢不會在PostgreSQL查詢中返回。PostgreSQL查詢表列註釋?

有沒有辦法查詢與每個column_name關聯的註釋?

+0

@mpen建議的重複地址表的評論,雖然類似沒有明確回答我的問題,關於_column_評論需要不同的方法。 –

回答

3

如何:

select col_description((table_schema||'.'||table_name)::regclass::oid, ordinal_position) as column_comment 
, * from information_schema.columns 
WHERE table_schema = 'schema_name' 
and table_name = 'table_name'; 
+1

非常好。謝謝。 – zedfoxus

0

你知道這顯示\dt+下可以逆向工程什麼的psql與-E

-E --echo-hidden回波就由\ d和其他反斜槓命令生成的實際查詢。你可以用它來研究psql的內部操作。這相當於將變量ECHO_HIDDEN設置爲打開。

psql -d test -E -c'\dt+ foo' 
********* QUERY ********** 
SELECT n.nspname as "Schema", 
    c.relname as "Name", 
    CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as "Type", 
    pg_catalog.pg_get_userbyid(c.relowner) as "Owner", 
    pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as "Size", 
    pg_catalog.obj_description(c.oid, 'pg_class') as "Description" 
FROM pg_catalog.pg_class c 
    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace 
WHERE c.relkind IN ('r','s','') 
     AND n.nspname !~ '^pg_toast' 
    AND c.relname ~ '^(foo)$' 
    AND pg_catalog.pg_table_is_visible(c.oid) 
ORDER BY 1,2; 
************************** 

你可以在這裏看到所有的信息PSQL節目。正如他們所說,教導那個人釣魚......?