Postgres : pg_restore/pg_dump 除了表的表 ID 之外的所有内容
目前我正在做类似的事情:
pg_dump -a -O -t my_table my_db > my_data_to_import.sql
我真正想要的是能够仅导入/导出数据,而不会导致与我的 autoid 字段发生冲突或覆盖现有数据。
也许我对整个过程的思考是错误的?
Currently I'm doing something like:
pg_dump -a -O -t my_table my_db > my_data_to_import.sql
What I really want is to be able to import/export just the data without causing conflicts with my autoid field or overwriting existing data.
Maybe I'm thinking about the whole process wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以使用 COPY 与列列表来转储和恢复数据从一张桌子。例如:
OID 是系统列之一。例如,它不包含在
SELECT * FROM my_table
中(您需要使用SELECT oid,* FROM my_table
)。 OID 与 CREATE TABLE 中的其他列一起创建的普通 id 列不同。并非每个表都有 OID 列。检查 default_with_oids 选项。如果它设置为关闭,那么您的表中可能没有 OID 列,但即使如此,您仍然可以使用WITH OIDS
选项创建带有 OID 的表。建议不要使用 OID 作为表的列(这就是为什么在 PostgreSQL 8.1 之前将 default_with_oids 设置为 off)。You can use COPY with column list to dump and restore just data from one table. For example:
OID is one of the system columns. For example it is not included in
SELECT * FROM my_table
(you need to useSELECT oid,* FROM my_table
). OID is not the same as ordinary id column created along with other columns in CREATE TABLE. Not every table has OID column. Check default_with_oids option. If it's set to off, then probalby you don't have OID column in your table, but even if so, then you can still create table with OID usingWITH OIDS
option. It's recommended not to use OID as table's column (that's why default_with_oids is set to off prior to PostgreSQL 8.1).