From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Daniel Gehrke <DGehrke(at)neusta(dot)de> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: MS SQL "isDate" equivalent in plpgsql? |
Date: | 2003-05-18 22:27:14 |
Message-ID: | 3EC808C2.6050608@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Daniel Gehrke wrote:
> I am porting from MS SQL 7.0 to PostgreSQL. In one Stored Procedure the
> function "isDate" is used. IsDate determines, whether the input string is a
> date or not:
>
> select isdate('05.15.2003');
> Result: 1
> select isdate('foobar');
> Result: 0
>
> Is there a function in plpgsql like that?
> Maybe someone has a self-written function that implements that?
>
I wrote something like you describe for someone else. It installs like a
"contrib" library, i.e.:
put the tarball in your source tree contrib folder
tar -xzf str_validate.tar.gz
cd str_validate
make
make install
psql mydatabase < str_validate.sql
You can grab a copy here:
http://www.joeconway.com/
See the README for (a little) more detail, but for your specific
question above, use is like this:
test=# select str_valid('05.15.2003','timestamp'::regtype);
str_valid
-----------
t
(1 row)
test=# select str_valid('foobar','timestamp'::regtype);
str_valid
-----------
f
(1 row)
Note, the above is for PostgreSQL 7.3.x or 7.4devel. If you are using
7.2.x, grab the version "str_validate for 7.2.X" and use like this:
test=# select str_valid('05.15.2003',(select oid from pg_type where
typname = 'timestamp'));
str_valid
-----------
t
(1 row)
test=# select str_valid('foobar',(select oid from pg_type where typname
= 'timestamp'));
str_valid
-----------
f
(1 row)
HTH,
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Matthew T. O'Connor | 2003-05-18 22:44:20 | Lists working? |
Previous Message | nolan | 2003-05-18 22:27:10 | pg_atoi problem with 7.3.2 |