pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
IsDate function in plpgsql
3+ messages / 3 participants
[nested] [flat]

* IsDate function in plpgsql
@ 2006-04-27 14:34 Sistemas C.M.P. <sistemascmp@redynet4.com.ar>
  2006-04-27 14:38 ` Re: IsDate function in plpgsql Ketema Harris <ketema@gmail.com>
  2006-04-27 14:40 ` Re: IsDate function in plpgsql Bricklen Anderson <banderson@presinet.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Sistemas C.M.P. @ 2006-04-27 14:34 UTC (permalink / raw)
  To: pgsql-admin

A few days ago, someone in this list gives  me a function (plpgsql) that evaluates if a string is a valid date or not. 
It returns 1 or 0 (valid/Not Valid)
The problem is that if the argument is a NULL field the function returns 1.
I don't have experience with plpgsql language. 
This is the function

begin
  perform $1::date;
  return 1;
exception when others then
  return 0;
end

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: IsDate function in plpgsql
  2006-04-27 14:34 IsDate function in plpgsql Sistemas C.M.P. <sistemascmp@redynet4.com.ar>
@ 2006-04-27 14:38 ` Ketema Harris <ketema@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Ketema Harris @ 2006-04-27 14:38 UTC (permalink / raw)
  To: Sistemas C.M.P. <sistemascmp@redynet4.com.ar>; pgsql-admin

I think someone will show you a better way, but if all you need to do is
account for the NULLS...

begin
  if $1 is null then
     return 0;
  else
     perform $1::date;
     return 1;
  end if;
exception when others then
return 0;
end


On 4/27/06 10:34 AM, "Sistemas C.M.P." <sistemascmp@redynet4.com.ar> wrote:

> A few days ago, someone in this list gives  me a function (plpgsql) that
> evaluates if a string is a valid date or not.
> It returns 1 or 0 (valid/Not Valid)
> The problem is that if the argument is a NULL field the function returns 1.
> I don't have experience with plpgsql language.
> This is the function
>  
> begin
>   perform $1::date;
>   return 1;
> exception when others then
>   return 0;
> end
> 

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: IsDate function in plpgsql
  2006-04-27 14:34 IsDate function in plpgsql Sistemas C.M.P. <sistemascmp@redynet4.com.ar>
@ 2006-04-27 14:40 ` Bricklen Anderson <banderson@presinet.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Bricklen Anderson @ 2006-04-27 14:40 UTC (permalink / raw)
  To: Sistemas C.M.P. <sistemascmp@redynet4.com.ar>; +Cc: pgsql-admin

Sistemas C.M.P. wrote:
> A few days ago, someone in this list gives  me a function (plpgsql) that 
> evaluates if a string is a valid date or not.
> It returns 1 or 0 (valid/Not Valid)
> The problem is that if the argument is a NULL field the function returns 1.
> I don't have experience with plpgsql language.
> This is the function
>  
> begin

>   perform $1::date;
>   return 1;
> exception when others then
>   return 0;
> end

create or replace function datetest (text) returns integer as $$
begin
     if ($1 is null) then
         return 0;
     end if;
     perform $1::date;
     return 1;
exception when others then
     return 0;
end;
$$ language plpgsql;



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-04-27 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-04-27 14:34 IsDate function in plpgsql Sistemas C.M.P. <sistemascmp@redynet4.com.ar>
2006-04-27 14:38 ` Ketema Harris <ketema@gmail.com>
2006-04-27 14:40 ` Bricklen Anderson <banderson@presinet.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox