本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
列出或搜尋指定資料表或檢視表的資料欄
您可以列出資料表的所有資料欄、檢視的所有資料欄,或在指定的資料庫和資料表中依名稱搜尋欄。
若要列出資料欄,請使用 SELECT *
查詢。在 FROM
子句中,指定 information_schema.columns
。在 WHERE
子句中,使用 table_schema='
來指定資料庫,使用 database_name
'table_name =
'
以指定具有您想要列出之資料欄的資料表或檢視。table_name
'
範例 – 列出指定資料表的所有資料欄
下面的範例查詢會列出資料表 rdspostgresqldb1_public_account
的所有資料欄。
SELECT * FROM information_schema.columns WHERE table_schema = 'rdspostgresql' AND table_name = 'rdspostgresqldb1_public_account'
下列資料表會顯示範例結果。
table_catalog | table_schema | table_name | column_name | ordinal_position | column_default | is_nullable | data_type | comment | extra_info | |
---|---|---|---|---|---|---|---|---|---|---|
1 | awsdatacatalog | rdspostgresql | rdspostgresqldb1_public_account | password | 1 | YES | varchar | |||
2 | awsdatacatalog | rdspostgresql | rdspostgresqldb1_public_account | user_id | 2 | YES | integer | |||
3 | awsdatacatalog | rdspostgresql | rdspostgresqldb1_public_account | created_on | 3 | YES | timestamp | |||
4 | awsdatacatalog | rdspostgresql | rdspostgresqldb1_public_account | last_login | 4 | YES | timestamp | |||
5 | awsdatacatalog | rdspostgresql | rdspostgresqldb1_public_account | 5 | YES | varchar | ||||
6 | awsdatacatalog | rdspostgresql | rdspostgresqldb1_public_account | username | 6 | YES | varchar |
範例 – 列出指定檢視的資料欄
下列範例查詢會針對檢視 default
列出 arrayview
資料庫中的所有資料欄。
SELECT * FROM information_schema.columns WHERE table_schema = 'default' AND table_name = 'arrayview'
下列資料表會顯示範例結果。
table_catalog | table_schema | table_name | column_name | ordinal_position | column_default | is_nullable | data_type | comment | extra_info | |
---|---|---|---|---|---|---|---|---|---|---|
1 | awsdatacatalog | 預設 | arrayview | searchdate | 1 | YES | varchar | |||
2 | awsdatacatalog | 預設 | arrayview | sid | 2 | YES | varchar | |||
3 | awsdatacatalog | 預設 | arrayview | btid | 3 | YES | varchar | |||
4 | awsdatacatalog | 預設 | arrayview | p | 4 | YES | varchar | |||
5 | awsdatacatalog | 預設 | arrayview | infantprice | 5 | YES | varchar | |||
6 | awsdatacatalog | 預設 | arrayview | sump | 6 | YES | varchar | |||
7 | awsdatacatalog | 預設 | arrayview | journeymaparray | 7 | YES | array(varchar) |
範例 – 在指定的資料庫與資料表中依名稱搜尋資料欄
下列範例查詢會在 sid
資料庫的 arrayview
檢視中搜尋 default
資料欄的中繼資料。
SELECT * FROM information_schema.columns WHERE table_schema = 'default' AND table_name = 'arrayview' AND column_name='sid'
下列資料表會顯示範例結果。
table_catalog | table_schema | table_name | column_name | ordinal_position | column_default | is_nullable | data_type | comment | extra_info | |
---|---|---|---|---|---|---|---|---|---|---|
1 | awsdatacatalog | 預設 | arrayview | sid | 2 | YES | varchar |