dbTalk Databases Forums  

timestamp error

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss timestamp error in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Robert Morgan
 
Posts: n/a

Default timestamp error - 05-20-2004 , 04:55 PM






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....

any ideas appreciated

Bob


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org


Reply With Quote
  #2  
Old   
joseph speigle
 
Posts: n/a

Default Re: timestamp error - 05-20-2004 , 11:55 PM






bob,

Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #3  
Old   
Colin Gillespie
 
Posts: n/a

Default Re: timestamp error - 05-21-2004 , 02:12 AM



Hi Bob,

In my tables I just have a default value of now() for my time.
So
CREATE TABLE t1(
c1 text,
time timestamp NOT NULL DEFAULT now()
);

Insert into t1 values ('a');

Colin

Quote:
-----Original Message-----
From: pgsql-novice-owner (AT) postgresql (DOT) org
[mailtogsql-novice-owner (AT) postgresql (DOT) org] On Behalf Of Robert Morgan
Sent: 20 May 2004 22:56
To: postgres
Subject: [NOVICE] timestamp error


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....

any ideas appreciated

Bob


---------------------------(end of
broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to
majordomo (AT) postgresql (DOT) org

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.