Saturday, May 31, 2008

Re: [GENERAL] Converting empty input strings to Nulls

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

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

No comments: