Thread: IsDate function in plpgsql
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;
perform $1::date;
return 1;
exception when others then
return 0;
end
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:
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
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;
I have a table called type: type ------- type_id integer tvalue smallint ... .. .. tvalue was a second key on this table which now turns out to be unnecessary. Before I can remove it I need to change the columns which reference it. I wanted to do this with alter table alter column using But the using clause I am using does not work. I think I may just be misunderstanding how this is done, but I could only find a few examples. Here is an example of what I have tried: alter table service.service alter column environment_tvalue type integer using select type.type.type_id where tvalue = environment_tvalue and typeset_id = 1; Does the expression in the using clause have to be a function? Any advice would be appreciated. Thanks, Craig