Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Converting empt...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 15685 of 17437
Post > Topic >>

Converting empty input strings to Nulls

by ken@[EMAIL PROTECTED] ("Ken Winter") May 31, 2008 at 01:40 PM

Applications accessing my PostgreSQL 8.0 database like to submit no-value
date column values as empty strings rather than as Nulls.  This, of
course,
causes this PG error:

SQL State: 22007
ERROR: invalid input syntax for type date: ""

I'm looking for a way to trap this bad input at the database level,
quietly
convert the input empty strings to Null, and store the Null in the date
column.  I tried a BEFORE INSERT OR UPDATE trigger evoking this function
...

CREATE OR REPLACE FUNCTION "public"."empty_string_to_null"()
RETURNS trigger AS
$BODY$
BEGIN
    IF CAST(NEW.birth_date AS text) =3D '' THEN
        NEW.birth_date =3D Null;
    END IF;
    RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

.... but an empty string still evokes the error even before this function
is
triggered.

Is there a way to convert empty strings to Nulls before the error is
evoked?

~ TIA
~ Ken


--=20
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 5 Posts in Topic:
Converting empty input strings to Nulls
ken@[EMAIL PROTECTED] (&  2008-05-31 13:40:05 
Re: Converting empty input strings to Nulls
pavel.stehule@[EMAIL PROT  2008-05-31 20:35:29 
Re: Converting empty input strings to Nulls
craig@[EMAIL PROTECTED]   2008-06-01 02:52:34 
Re: Converting empty input strings to Nulls
pgsql@[EMAIL PROTECTED]   2008-05-31 11:54:25 
Re: Converting empty input strings to Nulls
mgainty@[EMAIL PROTECTED]  2008-05-31 20:57:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 12:07:03 CST 2008.