pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ivan Sergio Borgonovo <mail@webthatworks.it>
To: pgsql-sql@postgresql.org
Subject: \COPY in psql using \e
Date: Wed, 2 Nov 2011 11:16:42 +0100
Message-ID: <20111102111642.153ff4e5@dawn.webthatworks.it> (raw)

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




Message-ID: <20111102111642.153ff4e5@dawn.webthatworks.it>
Permalink:  ../20111102111642.153ff4e5@dawn.webthatworks.it/
Also on:    postgresql.org/message-id/20111102111642.153ff4e5@dawn.webthatworks.it

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mail@webthatworks.it
  Subject: Re: \COPY in psql using \e
  In-Reply-To: <20111102111642.153ff4e5@dawn.webthatworks.it>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox