SELECT a.attname as col_name,a.atttypid as col_type FROM pg_catalog.pg_attribute a WHERE a.attnum > 0 AND NOT a.attisdropped AND a.attrelid = ( SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname ~ '^(tableName )$' AND pg_catalog.pg_table_is_visible(c.oid))
可以得到所有列的列名以及列类型,列类型对应的值如下:
bigint = 20;
smallint = 21;
integer = 23;
character = 1042;
character_var = 1043;
timestamp = 1114;
double = 701;
查询表格列名与类型的SQL
本文介绍了一段SQL查询语句,该语句能够获取指定表的所有列名及其对应的列类型。列类型包括bigint、smallint、integer等,并提供了这些类型的数值表示。
85

被折叠的 条评论
为什么被折叠?



