Re: [INTERFACES] COPY syntax

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [INTERFACES] COPY syntax
Дата
Msg-id 18008.903027434@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [INTERFACES] COPY syntax  (Eric Marsden <emarsden@mail.dotcom.fr>)
Список pgsql-interfaces
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

В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Eric Marsden
Дата:
Сообщение: Re: [INTERFACES] COPY syntax
Следующее
От: JohnDz
Дата:
Сообщение: pltcl