2

I am trying to export from a large postgres 8.1 table a couple of rows using

copy (select * from tablename limit 100) to 'absolute path to file';

but I get

ERROR:  syntax error at or near "(" at character 6.

Any ideas what might be going wrong ? By the way I am not super user in the database but I believe that would have produced a different kind of error. If you have any other idea to dump a couple of rows from SQL (in a format to insert them easily, without coding) other than using copy I open to suggestions.

4

2 回答 2

3

要克服版本 8.1 的缺点,您可以创建一个TEMPORARY TABLE并在以下位置使用它COPY TO

CREATE TEMP TABLE t_tmp AS
SELECT * FROM tablename LIMIT 100;

COPY t_tmp TO '/absolute/path/to/file';

温度。表会在会话结束时自动删除。如果您想保持连接打开,您可以显式删除表或将其包装在您回滚的事务中(已经写入文件的内容永远不会回滚。)

BEGIN;
CREATE ...;
COPY ...;
ROLLBACK;

或者您升级到更新的版本,这通常是一个非常好的主意。
PostgreSQL 8.1 已于 2010 年 11 月结束生命周期

于 2012-11-28T11:34:38.090 回答
0

在 postgresql 8.1 中,你不能COPYSELECT. 它是在 8.2 中添加的

看看这里的区别http://www.postgresql.org/docs/8.1/static/sql-copy.html和这里http://www.postgresql.org/docs/8.2/static/sql-copy.html

于 2012-11-28T11:00:02.863 回答