\COPY in psql using \e

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-sql(at)postgresql(dot)org
Subject: \COPY in psql using \e
Date: 2011-11-02 10:16:42
Message-ID: 20111102111642.153ff4e5@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I'm connecting to a DB with

psql -h host DB

once in psql I'd like to

\e

create temp table t1 ...;
\copy t1 from 'filename' ...
select * from t1;
[ESC]:x

what I get is:

CREATE TABLE
ERROR: syntax error at or near "select"
LINE 3: select * from t1;
^
\copy: ERROR: syntax error at or near "select"
LINE 3: select * from t1;
^

Now if I do:
\e

create temp table t1 ...;
\copy t1 from 'filename' ...
[ESC]:x
select * from t1;

everything works fine.

I've a lot of script files that actually contain mixed \COPY and
"plain" SQL statement

eg.

truncate table t1;
\copy t1 from 'filename1'
insert into d1...;

truncate table t2;
\copy t2 from 'filename2
insert into d1...;

that I execute as:

psql -h host DB < myscript.sql

and everything is fine.

Of course one solution could be to open a file in vi in a xterm and
execute it from another xterm. Anything cleaner?

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Peters 2011-11-02 16:36:19 Number timestamped rows
Previous Message Ross J. Reedstrom 2011-11-01 16:17:53 Re: select xpath ...