\COPY in psql using \e - Mailing list pgsql-sql

From Ivan Sergio Borgonovo
Subject \COPY in psql using \e
Date
Msg-id 20111102111642.153ff4e5@dawn.webthatworks.it
Whole thread Raw
List 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



pgsql-sql by date:

Previous
From: "Ross J. Reedstrom"
Date:
Subject: Re: select xpath ...
Next
From: "Jan Peters"
Date:
Subject: Number timestamped rows