Re: migrating from mysql: need to convert empty string to null - Mailing list pgsql-general

From Dave Lee
Subject Re: migrating from mysql: need to convert empty string to null
Date
Msg-id cb13bf640806181731m4ea75eafra298371cc4153520@mail.gmail.com
Whole thread Raw
In response to Re: migrating from mysql: need to convert empty string to null  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: migrating from mysql: need to convert empty string to null
List pgsql-general
On Wed, Jun 18, 2008 at 3:25 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> There isn't any really nice way to do that :-(.  You could put a wrapper
> function around int4in but it would not help, because the internal API
> for datatype input functions doesn't support having them return NULL
> (see InputFunctionCall in the sources).

I've read src/backend/utils/fmgr/README and it states that returning
NULL is just a matter of setting isnull to true in the
FunctionCallInfo struct, and provides a convenience macro,
PG_RETURN_NULL. But then, in InputFunctionCall, I presume you're
referring to the logic that that only allows NULL to be returned if
the source input string is also NULL, otherwise raising an error. At a
basic level, you're suggesting I need to take out this NULL check in
InputFunctionCall to get the capability I'm looking for?

Any idea why the input functions were designed this way? For users
migrating from other RDBMs, if no one else, being able to return NULL
from an input function seems to be a valuable feature. I might use
this hacked functionality to return NULL for '0000-00-00' dates which
MySQL foolishly accepts. Maybe it's only useful to former MySQL users

thanks,
Dave

pgsql-general by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: renumber table
Next
From: Jeff Davis
Date:
Subject: pg_locks "at-a-glance" view