在PostgreSQL中显示表结构和表列表
参见英文答案 >
PostgreSQL “DESCRIBE TABLE”18个
我曾在几个以前的项目中使用过MySQL.但现在有了 决定改用PostgreSQL.不是说版本8也适用于此, 我在工作中遇到的其他操作系统. 但是,有两个最有用的命令似乎丢失了: >显示表格 因为我的原型数据库在家里的NetBSD服务器上,而我的 当我处于初始阶段时,我需要一个信息丰富的方式来犯错误 我无法相信PostgreSQL没有办法告诉我是什么 当然必须有.但我似乎无法从这对夫妇身上找到答案 请赐教.请注意,PostgreSQL-ish SQL是什么
按照
Documentation
SELECT table_schema || '.' || table_name as show_tables FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog','information_schema'); 为了更方便,使它成为一种功能 create or replace function show_tables() returns SETOF text as $$ SELECT table_schema || '.' || table_name as show_tables FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog','information_schema'); $$ language sql; 所以我们可以使用表格 select show_tables() 对于表格说明 select column_name,data_type,character_maximum_length from INFORMATION_SCHEMA.COLUMNS where table_name ='table_name'; 作为一个功能 create or replace function describe_table(tbl_name text) returns table(column_name varchar,data_type varchar,character_maximum_length int) as $$ select column_name,character_maximum_length from INFORMATION_SCHEMA.COLUMNS where table_name = $1; $$ language 'sql'; select * from describe_table('a_table_name'); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |