Thread: checking date format with postgresql without creating a table

checking date format with postgresql without creating a table

From
Neil Zanella
Date:
Hello,

I would like to be able to check whether some date is a valid date by
asking postgresql? Is this possible? The idea is that when an invalid
date is entered into a postgresql table an error is output. Thus to
check the validity of a date from JDBC in a rather lazy way one could
create a table called checkdate with a single column of type date and
insert into that column. If the database generates an error than an
SQLException is output and the user knows that the date is incorrect
and thus needs to prompt for a date again. Now I want to do the
above without having to create any tables. Is this possible?

Thanks,

Neil


Re: checking date format with postgresql without creating

From
Alvaro Herrera
Date:
On Mon, 19 Nov 2001, Neil Zanella wrote:

> Hello,
>
> I would like to be able to check whether some date is a valid date by
> asking postgresql? Is this possible?

Sure:

alvherre=> select '28 feb 2001'::date;
    date
------------
 2001-02-28
(1 row)

alvherre=> select '29 feb 2001'::date;
ERROR:  Bad date external representation '29 feb 2001'

You don't need a table to do it.

--
Alvaro Herrera (<alvherre[@]atentus.com>)


Re: checking date format with postgresql without creating

From
Neil Zanella
Date:
Thanks. I notice that this method is not SQL compliant and thus
is not portable to other DBMSs.

Thanks,

Neil

On Tue, 20 Nov 2001, Alvaro Herrera wrote:

> On Mon, 19 Nov 2001, Neil Zanella wrote:
>
> > Hello,
> >
> > I would like to be able to check whether some date is a valid date by
> > asking postgresql? Is this possible?
>
> Sure:
>
> alvherre=> select '28 feb 2001'::date;
>     date
> ------------
>  2001-02-28
> (1 row)
>
> alvherre=> select '29 feb 2001'::date;
> ERROR:  Bad date external representation '29 feb 2001'
>
> You don't need a table to do it.
>
> --
> Alvaro Herrera (<alvherre[@]atentus.com>)
>