Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6]) by hub.org (8.8.8/8.7.5) with ESMTP id MAA05214 for ; Thu, 13 Aug 1998 12:57:29 -0400 (EDT) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id MAA18011; Thu, 13 Aug 1998 12:57:14 -0400 (EDT) To: emarsden@mail.dotcom.fr cc: pgsql-interfaces@postgreSQL.org Subject: Re: [INTERFACES] COPY syntax In-reply-to: Your message of 13 Aug 1998 18:41:46 +0200 Date: Thu, 13 Aug 1998 12:57:14 -0400 Message-ID: <18008.903027434@sss.pgh.pa.us> From: Tom Lane Eric Marsden 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