postgresql数据库 怎么写sql语句得到数据表中字段名称搜了一个:select name from syscolumns where id=object_id('表名称')
不适合psql,ERROR: relation "syscolumns" does not exist********** 错误 **********ERROR: relation "syscolumns" does not exist
SQL 状态: 42P01
不适合psql,ERROR: relation "syscolumns" does not exist********** 错误 **********ERROR: relation "syscolumns" does not exist
SQL 状态: 42P01
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| context | varchar(45) | | PRI | default | |
| extension | varchar(45) | | PRI | | |
| priority | varchar(5) | | PRI | 1 | |
| application | varchar(45) | | | | |
| args | varchar(255) | YES | | NULL | |
| descr | text | YES | | NULL | |
| flags | int(1) | | | 0 | |
+-------------+--------------+------+-----+---------+-------+
我试了一下:select * from pg_attribute
显示出了所有数据库的所有字段名称,我不知道后面的where 条件语句应该怎样写,做的的请发言,帮一下
pg_attribute 表存储关于表的字段的信息。数据库里每个表的每个字段都在 pg_attribute 里有一行。还有用于索引,以及所有在 pg_class 里有记录的对象。术语属性等效于列/字段,使用它是历史原因。
select attname,atttypid from pg_attribute where attrelid = ( select relfilenode from pg_class where relname = '你的表名') and attnum > 0;
t_girl=# \d t
Table "public.t"
Column | Type | Modifiers
----------+---------------+------------------------------------------------
id | integer | not null default nextval('t_id_seq'::regclass)
username | character(20) | not null
Indexes:
"t_pkey" PRIMARY KEY, btree (id)t_girl=# select attname,atttypid from pg_attribute where attrelid = ( select relfilenode from pg_class where relname = 't') and attnum > 0;
attname | atttypid
----------+----------
id | 23
username | 1042
(2 rows)t_girl=#
想看表结构打
\d [tablename]