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.

2
  • Please copy-and-paste the exact command you're using, including the actual table name and file name. Commented Nov 28, 2012 at 10:35
  • You are aware that 8.1 has been deprecated and de-supported for a long time? Commented Nov 28, 2012 at 11:45

2 Answers 2

3

To overcome the shortcoming of version 8.1 you can create a TEMPORARY TABLE and use it in COPY TO:

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

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

Temp. tables are dropped at the end of a session automatically. If you want to keep the connection open you could drop the table explicitly or wrap it in a transaction which you roll back (what's already written to the file is never rolled back.)

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

Or you upgrade to a more recent version, which would be a very good idea in general.
PostgreSQL 8.1 has reached end of life in Nov. 2010.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that worked fine. As far as the newer version I know but as a developer I am told to keep using that.
@user1845360: You have my sympathies. ;)
0

In postgresql 8.1 you cant COPY from SELECT. It was added in 8.2

Look at the differences here http://www.postgresql.org/docs/8.1/static/sql-copy.html and here http://www.postgresql.org/docs/8.2/static/sql-copy.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.