Re: Converting empty input strings to Nulls - Mailing list pgsql-general

From Craig Ringer
Subject Re: Converting empty input strings to Nulls
Date
Msg-id 48419E72.3090603@postnewspapers.com.au
Whole thread Raw
In response to Re: Converting empty input strings to Nulls  ("Pavel Stehule" <pavel.stehule@gmail.com>)
List pgsql-general
Pavel Stehule wrote:
> Hello
>
> 2008/5/31 Ken Winter <ken@sunward.org>:
>> ... 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?
>>
> no - it's not possible. And some "magic" fix in triggers is bad style.

The rule system may be able to handle this transformation (using insert
rules or an updateable view). Getting it to work could be a bit arcane,
though, and having never really delved into the rule system I can't be
of much help.

See:

http://www.postgresql.com.cn/docs/8.3/static/rules.html

http://www.postgresql.com.cn/docs/8.3/static/sql-createrule.html

http://wiki.postgresql.org/wiki/Updatable_views

http://wiki.postgresql.org/wiki/Introduction_to_PostgreSQL_Rules_-_Making_entries_which_can't_be_altered

Personally, though, if at all possible I'd fix the broken client
application.  "" is NOT NULL . If you don't fix it, consider at least
clearly documenting the wacky behaviour and if possible applying it only
to an updatable view rather than the base table.

--
Craig Ringer

pgsql-general by date:

Previous
From: "Pavel Stehule"
Date:
Subject: Re: Converting empty input strings to Nulls
Next
From: Jeff Davis
Date:
Subject: Re: Converting empty input strings to Nulls