Thread: Function Returning a Set of Composite Value
Hi All ,
I have a function f_wrapper(seq,pat) which returns a composite value of type (int,int[][]);
I am aware that I can run a query somthing like this to get it working
select * from f_wrapper('XYZ,'X') as m1(mid int,match int[][]);
but I want to pass another table column as parameter to function. - select f_wrapper( t.seq,'X') from t_sequence t;
this return result which looks like -
(0,"{{0,2,2}}")
(1,"{{10,2,2}}")
when I try to parse this result in following way -
select f_wrappwe(t.seq,'X') frm t_sequence t as m1(mid int,match int[][]) ; I get following syntax error
ERROR: syntax error at or near "int"
LINE 1: ...f_wrapper(seq,'MK') from nik_small_file as m1(mid int,match ...
^
any idea why I am getting this error or what is the alternative to parse composite value in select column ?
my purpose is to to show some column from table+(result from f_wrapper function) but I am not able to parse f_wrapper result in required column without calling f_wrapper twice like this -
select (f_wrapper(seq,'MK')).mid , (f_wrapper(seq,'MK')).match from nik_small_file;
since my f_wrapper is going to be a heavy function so I can't afford to call it twice.
any suggestion regarding this will be helpful.
Regards,
Nikhil
PS: Earlier I have sent same question to pgsql-novice as well but then I realised that this might be more relevant on this list. sorry for posting it twice.
I have a function f_wrapper(seq,pat) which returns a composite value of type (int,int[][]);
I am aware that I can run a query somthing like this to get it working
select * from f_wrapper('XYZ,'X') as m1(mid int,match int[][]);
but I want to pass another table column as parameter to function. - select f_wrapper( t.seq,'X') from t_sequence t;
this return result which looks like -
(0,"{{0,2,2}}")
(1,"{{10,2,2}}")
when I try to parse this result in following way -
select f_wrappwe(t.seq,'X') frm t_sequence t as m1(mid int,match int[][]) ; I get following syntax error
ERROR: syntax error at or near "int"
LINE 1: ...f_wrapper(seq,'MK') from nik_small_file as m1(mid int,match ...
^
any idea why I am getting this error or what is the alternative to parse composite value in select column ?
my purpose is to to show some column from table+(result from f_wrapper function) but I am not able to parse f_wrapper result in required column without calling f_wrapper twice like this -
select (f_wrapper(seq,'MK')).mid , (f_wrapper(seq,'MK')).match from nik_small_file;
since my f_wrapper is going to be a heavy function so I can't afford to call it twice.
any suggestion regarding this will be helpful.
Regards,
Nikhil
PS: Earlier I have sent same question to pgsql-novice as well but then I realised that this might be more relevant on this list. sorry for posting it twice.
Check out the all-new Messenger 9.0! Click here.