From: Tom Lane <tgl@sss.pgh.pa.us>
To: emarsden@mail.dotcom.fr
Cc: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] COPY syntax
Date: Thu, 13 Aug 1998 12:57:14 -0400
Message-ID: <18008.903027434@sss.pgh.pa.us> (raw)
In-Reply-To: <m24svgsuk5.fsf@cook.onecert.fr>
Eric Marsden <emarsden@mail.dotcom.fr> writes:
> Is it possible to use functions in
> COPY input? Specifically, I am trying to do this
> COPY attributes FROM 'home/ecm/prog/database/attributes.data';
> where the file contains entries like (with tabs)
> nextval('attribute_id_sequence') Control and Monitoring \N
Nope, won't work. COPY handles literal data only --- if it were smart
enough to do SQL expressions then we wouldn't have to have this weird \N
kluge for null values. (I think there are a few tiny exceptions, like
you could put "now" as the value for a datetime field and the expected
thing would happen during COPY IN. That's because the literal-string-
to-data-value parser for type datetime implements that conversion all
by itself. But nextval() is definitely an SQL expression.)
You should use a series of INSERT commands if you need to do SQL
calculations while inserting data. For instance, I have an app that
uses nextval() to assign ID numbers like yours, and it issues tons
of commands like this:
INSERT INTO FEHistory_3 (accountID, instrumentID, orderType,
numContracts, orderTime, simStatus, realStatus, sequenceNo, orderPrice,
orderDivisor, ifDonePrice) VALUES(13, 120, 'S', 1, '1998-07-16 18:00:00 GMT',
'A', '-', nextval('FEHistory_3_Seq'), 10603, 100, 10574)
regards, tom lane
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-interfaces@postgresql.org
Cc: tgl@sss.pgh.pa.us, emarsden@mail.dotcom.fr
Subject: Re: [INTERFACES] COPY syntax
In-Reply-To: <18008.903027434@sss.pgh.pa.us>
* 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