Search Postgresql Archives

copy from with trigger

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm trying to copy from a tab delimited file.  The dates inside the file
are Unix timestamp style dates.
I thought the following script would do the trick, but it just gives me
an error saying 
ERROR:  invalid input syntax for type timestamp: "1238736600"
CONTEXT:  COPY testtable line 1, column acquire_time: "1238736600"

Its mapping the right value to the write column, but it doesn't appear
to be going through the trigger.
Here's the relevant setup info.  Just assume the upload file is one unix
style date.

Thanks for any help, I'm rather confused.

CREATE TABLE testtable
(
  acquire_time timestamp without time zone NOT NULL
);
CREATE FUNCTION importData() RETURNS trigger AS $$
    BEGIN
	NEW.acquire_time := TIMESTAMP 'epoch' + int4(NEW.acquire_time) *
INTERVAL '1 SECOND';
        RETURN NEW;
    END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER btestinsert
  BEFORE INSERT
  ON testtable
  FOR EACH ROW
  EXECUTE PROCEDURE importdata();


COPY testtable 
(
  acquire_time
)
FROM '/home/testy/test.tab' WITH DELIMITER E'\t' CSV;



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux