With the following query, we can get a list of column names and datatype of a table in PostgreSQL.
通过下面的查询,我们可以在PostgreSQL中获得一个表的列名和数据类型列表。
4 个解决方案
#1
30
select column_name,data_type
from information_schema.columns
where table_name = 'table_name';
with the above query you can columns and its datatype
使用上述查询,您可以列及其数据类型
#2
29
Open psql commande line and type :
打开psql命令行和类型:
\d+ table_name
#3
6
SELECT
a.attname as "Column",
pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
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 ~ '^(hello world)$'
AND pg_catalog.pg_table_is_visible(c.oid)
);
More info on it : http://www.postgresql.org/docs/9.3/static/catalog-pg-attribute.html
关于它的更多信息:http://www.postgresql.org/docs/9.3/static/catalog-pg-attribute.html
#4
1
To get information about the table's column, you can use:
要获取关于该表列的信息,您可以使用:
\dt+ [tablename]
To get information about the datatype in the table, you can use:
要获取表中数据类型的信息,可以使用:
\dT+ [datatype]
#1
30
select column_name,data_type
from information_schema.columns
where table_name = 'table_name';
with the above query you can columns and its datatype
使用上述查询,您可以列及其数据类型
#2
29
Open psql commande line and type :
打开psql命令行和类型:
\d+ table_name
#3
6
SELECT
a.attname as "Column",
pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
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 ~ '^(hello world)$'
AND pg_catalog.pg_table_is_visible(c.oid)
);
More info on it : http://www.postgresql.org/docs/9.3/static/catalog-pg-attribute.html
关于它的更多信息:http://www.postgresql.org/docs/9.3/static/catalog-pg-attribute.html
#4
1
To get information about the table's column, you can use:
要获取关于该表列的信息,您可以使用:
\dt+ [tablename]
To get information about the datatype in the table, you can use:
要获取表中数据类型的信息,可以使用:
\dT+ [datatype]