一、場景還原
前端小林問我,它從前端的返回的某些字段,想知道那個表有這個字段,它想操作這個表……
二、sql語句
SELECT *
FROM information_schema. COLUMNS
WHERE COLUMN_NAME = 'storename';
SELECT c.relname AS "表名",a.attname AS "字段名",c.oid
FROM pg_class c
LEFT JOIN pg_attribute a ON a.attrelid = c.oid
WHERE c.relname NOT LIKE 'pg_%'
-- AND c.relname = 'kx_store'
AND a.attname = 'storename';
補充:postgresql數(shù)據(jù)庫查詢所有字段詳細信息,包括描述
把里邊的public改成相應模式名(默認為public,可不改)
table_name改成對應表名稱
SELECT AA.*,BB.DESC FROM
(
SELECT
A.ORDINAL_POSITION AS COL_NUM,
A.COLUMN_NAME AS COL_NAME,
A.DATA_TYPE AS COL_TYPE,
A.CHARACTER_MAXIMUM_LENGTH AS COL_LEN,
A.NUMERIC_PRECISION AS COL_PREC,
A.DATETIME_PRECISION AS COL_TIME_PREC,
A.IS_NULLABLE AS COL_NULLABLE,
A.COLUMN_DEFAULT AS COL_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS A
WHERE A.TABLE_SCHEMA = 'public' AND A.TABLE_NAME = 'table_name'
)
AS AA LEFT JOIN
(
SELECT
OBJSUBID,
DESCRIPTION AS DESC
FROM PG_DESCRIPTION
WHERE OBJOID =
(
SELECT RELID FROM PG_STAT_ALL_TABLES WHERE SCHEMANAME = 'public' AND RELNAME = 'table_name'
)
)
AS BB ON AA.COL_NUM = BB.OBJSUBID ORDER BY AA.COL_NUM;
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
您可能感興趣的文章:- postgresql 查詢字符串中是否包含某字符的操作
- PostgreSQL 慢查詢SQL跟蹤操作
- PostgreSQL 實現(xiàn)子查詢返回多行的案例
- Visual Studio Code(VS Code)查詢PostgreSQL拓展安裝教程圖解
- PostgreSQL 實現(xiàn)給查詢列表增加序號操作
- 基于postgreSql 常用查詢小結(jié)