[英].schema for postgres
I'm migrating a database from sqlite3 to postgres and am wondering if there are any short tutorials that can teach me the new syntax. 我正在将数据库从sqlite3迁移到postgres,我想知道是否有任何简短的教程可以教我新的语法。
Also, as a short term question, how do I see the schema of a postgres table which is equivalent to .schema
in sqlite? 另外,作为一个短期问题,我如何看到postgres表的模式,它等同于sqlite中的
.schema
?
You could use pg_dump command line utility, ie: 您可以使用pg_dump命令行实用程序,即:
pg_dump --table <table_name> --schema-only <database_name>
Depending on your environment you probably need to specify connection options (-h, -p, -U switches). 根据您的环境,您可能需要指定连接选项(-h,-p,-U开关)。
You could use \\d
from within psql
: 您可以在
psql
使用\\d
:
=> \?
...
Informational
(options: S = show system objects, + = additional detail)
\d[S+] list tables, views, and sequences
\d[S+] NAME describe table, view, sequence, or index
...
=> \d people
Table "public.people"
Column | Type | Modifiers
------------------------+-----------------------------+-----------------------------------------------------
id | integer | not null default nextval('people_id_seq'::regclass)
created_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
...
Indexes:
"people_pkey" PRIMARY KEY, btree (id)
...
Check constraints:
"chk_people_latlng" CHECK ((lat IS NULL) = (lng IS NULL))
....
You can also root around in the information_schema
if you're not inside psql
. 如果你不在
psql
中,你也可以在information_schema
根。
If you are using psql (and \\d... ) then you can 如果您正在使用psql(和\\ d ...),那么您可以
\set ECHO_HIDDEN
to see the sql for the queries that psql is executing to put together the \\d... output-- this is useful not only as sql syntax examples but it also shows you where find, and how to connect, the database metadata. 查看psql正在执行的查询的sql以将\\ d ...输出放在一起 - 这不仅可以用作sql语法示例,还可以显示查找和如何连接数据库元数据的位置。
To get the schema name for a table you can: 要获取表的模式名称,您可以:
SELECT n.nspname AS schema_name,
c.relname AS table_name
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = '<table_name>'
;
(don't know how that compares to .schema) (不知道与.schema相比如何)
Maybe you can use a PostgreSQL Cheat Sheet: 也许你可以使用PostgreSQL备忘单:
http://www.postgresonline.com/special_feature.php?sf_name=postgresql83_cheatsheet&outputformat=html http://www.postgresonline.com/special_feature.php?sf_name=postgresql83_cheatsheet&outputformat=html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.