Connecting Tech Pros Worldwide Help | Site Map

how to make this function work....

Newbie
 
Join Date: May 2008
Posts: 27
#1: Jun 9 '08
hi.. i have this procedure.. but its not working.. its showing some syntax errors.. how can i make this work.. please help



create or replace function test(text)
returns integer
as
$$
Declare
x varchar;
y varchar;
z varchar;
Begin
z := select xpath('/F/@CT:I',''||$1||'',ARRAY[ARRAY['CT','urn:PointCross-ChangeTracker']]);
execute z into y;
return y;
end;
$$
language 'plpgsql';
Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 292
#2: Jun 9 '08

re: how to make this function work....


Quote:

Originally Posted by ravysters

hi.. i have this procedure.. but its not working.. its showing some syntax errors.. how can i make this work.. please help



create or replace function test(text)
returns integer
as
$$
Declare
x varchar;
y varchar;
z varchar;
Begin
z := select xpath('/F/@CT:I',''||$1||'',ARRAY[ARRAY['CT','urn:PointCross-ChangeTracker']]);
execute z into y;
return y;
end;
$$
language 'plpgsql';

Maybe you'll show that errors. By the way if z is varchar shouldn't you put
Expand|Select|Wrap|Line Numbers
  1. select xpath('/F/@CT:I',''||$1||'',ARRAY[ARRAY['CT','urn:PointCross-ChangeTracker']]);
  2.  
between apos.
Expand|Select|Wrap|Line Numbers
  1. z:='select xpath('/F/@CT:I',''||$1||'',ARRAY[ARRAY['CT','urn:PointCross-ChangeTracker']]);'
  2.  
and why do you write ''||$1||'' are you using there quotation or is it double apos?
Newbie
 
Join Date: May 2008
Posts: 27
#3: Jun 10 '08

re: how to make this function work....


i am sorry.. i accidentally reported instead of replying...

thanks for the reply...the function is working...

but i have a new problem.. type casting..how can i do that in postgres...
i went through the manual... but wasn't that helpful...

consider the following..

declare x varchar;
execute 'select xpath()' into x;
return x;

how can i convert x from varchar to integer...
help me..
Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 292
#4: Jun 10 '08

re: how to make this function work....


Quote:

Originally Posted by ravysters

i am sorry.. i accidentally reported instead of replying...

thanks for the reply...the function is working...

but i have a new problem.. type casting..how can i do that in postgres...
i went through the manual... but wasn't that helpful...

consider the following..

declare x varchar;
execute 'select xpath()' into x;
return x;

how can i convert x from varchar to integer...
help me..

doesn't simple
Expand|Select|Wrap|Line Numbers
  1. return x::integer
  2.  
work? if not maybe you should write your own cast function.
Newbie
 
Join Date: May 2008
Posts: 27
#5: Jun 10 '08

re: how to make this function work....


hi.. even after doing that i am gettting this error..

invalid input syntax for integer: ...


i even used select cast( x as integer)..


dint work either man..
Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 292
#6: Jun 10 '08

re: how to make this function work....


Quote:

Originally Posted by ravysters

hi.. even after doing that i am gettting this error..

invalid input syntax for integer: ...


i even used select cast( x as integer)..


dint work either man..

What does
Expand|Select|Wrap|Line Numbers
  1. execute 'select xpath()' into x;
  2.  
produce?
Reply