From: | joseph speigle <joe(dot)speigle(at)jklh(dot)us> |
---|---|
To: | postgres <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: timestamp error |
Date: | 2004-05-21 04:55:36 |
Message-ID: | 20040521045536.GA27558@www.sirfsup.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
bob,
> Hi I have a form that inserts data to the DB. One field is timestamp
> type this field is not always filled out but postgres wont accept '' or
> null and gives the error (or maybe php gives the error)..
>
> query failed: ERROR: Bad timestamp external representation '' in....
--
I see two solutions:
1) always add a timestamp with php
maybe (???) this:
$current=time(); //get current UNIX timestamp
2) use a trigger like this one and remove it from the update/insert clause
CREATE OR REPLACE FUNCTION enterdate() RETURNS trigger AS '
DECLARE
BEGIN
NEW.tstamp := now();
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
CREATE TRIGGER mytrig BEFORE INSERT ON t_text
FOR EACH ROW EXECUTE PROCEDURE enterdate();
INSERT INTO t_text (id) VALUES ('2');
SELECT * FROM t_text;
-- http://dotgeek.org/guruarticles.php?guru=view&id=27
-- may 12, 2004
good luck,
joe speigle
www.sirfsup.com
From | Date | Subject | |
---|---|---|---|
Next Message | Colin Gillespie | 2004-05-21 07:12:48 | Re: timestamp error |
Previous Message | hendro | 2004-05-21 02:37:53 | Migrating from SQL-Server |