免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3924 | 回复: 0
打印 上一主题 下一主题

PostgreSQL pg_dump ERROR: syntax error at or near "old" [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-22 19:12 |只看该作者 |倒序浏览
使用pg_dump 9.0.1版本导出PostgreSQL 8.4.2,当备份到某个表时报了一个错误.
pg_dump: SQL command failed
pg_dump: Error message from server: ERROR:  syntax error at or near "old"
LINE 1: ...erid, create_time, update_time, showvote, isshow, old, showi...
                                                             ^
pg_dump: The command was: COPY wapmarket.topics (id, title, content, orderid, create_time, update_time, showvote, isshow, old, showindex) TO stdout;
pg_dump: *** aborted because of error

排查过程如下:
1. 在8.4.2数据库服务端登录到psql命令行下面,
postgres=# create table tbl_test (old boolean);
ERROR:  syntax error at or near "old"
LINE 1: create table tbl_test (old boolean);
                               ^
postgres=# create table tbl_test ("old" boolean);
CREATE TABLE
postgres=# select old from tbl_test;
ERROR:  OLD used in query that is not in a rule
LINE 1: select old from tbl_test;
               ^
postgres=# select "old" from tbl_test;
old
-----
(0 rows)
在PostgreSQL8.4 版本中old作为关键字使用,查询时必须使用双引号。
COPY也是一样,
postgres=# copy tbl_test (old) to stdout;
ERROR:  syntax error at or near "old"
LINE 1: copy tbl_test (old) to stdout;
                       ^
postgres=# copy tbl_test ("old") to stdout;
postgres=#

2. 在PostgreSQL9.0.1数据库服务端中登录到psql环境再测试一遍,
rmt_rescue=> create table tbl_test (old boolean);
CREATE TABLE
rmt_rescue=> select old from tbl_test;
old
-----
(0 rows)
不需要加双引号,
因此使用9.0.1的pg_dump导出8.4的数据库遇到old字段会报错.
解决办法是使用8.4的pg_dump导出8.4的数据库.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP