Re: implicit cast of empty string to timestamp - Mailing list pgsql-general

From James Harper
Subject Re: implicit cast of empty string to timestamp
Date
Msg-id AEC6C66638C05B468B556EA548C1A77DAF0812@trantor
Whole thread Raw
In response to implicit cast of empty string to timestamp  ("James Harper" <james.harper@bendigoit.com.au>)
List pgsql-general
> am  10.02.2006, um 20:22:57 +1100 mailte James Harper folgendes:
> > Is there anything I can do to make postgres allow an implicit cast
of an
> > empty string to a timestamp, so that a badly behaved application can
do:
>
> > INSERT INTO SomeTable (timestampfield) VALUES ('')
>
> You can't insert a empty string into a timestamp, IIRC.

No, and if someone tries I want to put a NULL in there.

I had hoped the following might work (syntax is from memory):

CREATE SCHEMA fnord;
SET search_path TO fnord;
CREATE FUNCTION fnord.timestamp (text) RETURNS timestamp LANGUAGE SQL AS
$$
SELECT pg_catalog.timestamp('20010101') $$;

SELECT CAST(text '20060101' AS timestamp);
SELECT CAST(text '' AS timestamp);

I had hoped that my 'timestamp' function would have overridden the
unqualified function call in the cast, but it was not to be :(

Curiously tho, \df didn't even acknowledge the 'timestamp' function in
the database, even though it was in the pg_proc's table.

Oh well.

James


pgsql-general by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: implicit cast of empty string to timestamp
Next
From: "James Harper"
Date:
Subject: Re: implicit cast of empty string to timestamp