Re: [SQL] function returning result set of varying column

2008-06-03 Thread Pavel Stehule
2008/6/3 maria s <[EMAIL PROTECTED]>: > Hi Pavel Stehule, > Thanks for your reply. > > If I want to return a string and an array how should I do it? > The problem is as I explained before. postgres=# create or replace function foo(j integer, out a varchar, out b varchar[]) as $$ begin a := 'kuku';

Re: [SQL] function returning result set of varying column

2008-06-03 Thread Ivan Sergio Borgonovo
On Tue, 3 Jun 2008 10:06:45 -0400 "maria s" <[EMAIL PROTECTED]> wrote: > Hi Ivan, > If I have to know the column names then I can't use the Functions. > As I said before, the columns will vary. or As Pavel Stehule said > I will use arrays. > > Is anyone can show an example of returning a record w

Re: [SQL] function returning result set of varying column

2008-06-03 Thread maria s
Hi Pavel Stehule, Thanks for your reply. If I want to return a string and an array how should I do it? The problem is as I explained before. I have 2 tables. For a single entry E1 in one table(t1), I have to fetch all the matching entries for E1 from the other table(t2), K1,..Kn, M1...Mn

Re: [SQL] function returning result set of varying column

2008-06-03 Thread Pavel Stehule
2008/6/3 maria s <[EMAIL PROTECTED]>: > Hi Ivan, > If I have to know the column names then I can't use the Functions. > As I said before, the columns will vary. or As Pavel Stehule said > I will use arrays. > > Is anyone can show an example of returning a record with string and array? postgres=#

Re: [SQL] function returning result set of varying column

2008-06-03 Thread maria s
Hi Ivan, If I have to know the column names then I can't use the Functions. As I said before, the columns will vary. or As Pavel Stehule said I will use arrays. Is anyone can show an example of returning a record with string and array? Thanks, Maria On Tue, Jun 3, 2008 at 9:57 AM, Ivan Sergio Bo

Re: [SQL] function returning result set of varying column

2008-06-03 Thread Ivan Sergio Borgonovo
On Tue, 3 Jun 2008 09:41:27 -0400 "maria s" <[EMAIL PROTECTED]> wrote: > Thanks for all your replies. > > Actually I don't know the number of columns that I am going to > return. > > I have 2 tables. For a single entry E1 in one table(t1), I have > to fetch all the matching entries for E1 from

Re: [SQL] function returning result set of varying column

2008-06-03 Thread Pavel Stehule
2008/6/3 maria s <[EMAIL PROTECTED]>: > Thanks for all your replies. > > Actually I don't know the number of columns that I am going to return. > > I have 2 tables. For a single entry E1 in one table(t1), I have to fetch > all the matching entries for E1 from the other table(t2), K1,..Kn. > and f

Re: [SQL] function returning result set of varying column

2008-06-03 Thread maria s
Thanks for all your replies. Actually I don't know the number of columns that I am going to return. I have 2 tables. For a single entry E1 in one table(t1), I have to fetch all the matching entries for E1 from the other table(t2), K1,..Kn. and finally the function should return E1, K1..Kn. So I

Re: [SQL] function returning result set of varying column

2008-06-03 Thread Ivan Sergio Borgonovo
On Tue, 3 Jun 2008 09:01:02 -0400 "maria s" <[EMAIL PROTECTED]> wrote: > Hi Friends, > Thanks for all your for the reply. > > I tried the function and when I execute it using > select * from myfunction() > it says > ERROR: a column definition list is required for functions > returning "record" >

Re: [SQL] function returning result set of varying column

2008-06-03 Thread Bart Degryse
As I wrote before you will have to define your fields when querying the function, eg. select * from myfunction() as ("field1" integer, "field2" text, ...) So suppose you have a table like this CREATE TABLE sometable ( "id" serial, "sometextfield" text, "aninteger" int, "andavarchar" varcha

Re: [SQL] function returning result set of varying column

2008-06-03 Thread maria s
Hi Friends, Thanks for all your for the reply. I tried the function and when I execute it using select * from myfunction() it says ERROR: a column definition list is required for functions returning "record" Could you please help me to fix this error? Thanks so much for your help. -maria On T

Re: [SQL] function returning result set of varying column

2008-06-03 Thread Bart Degryse
Hi Maria, Try something like CREATE OR REPLACE FUNCTION myfunction() RETURNS SETOF RECORD AS $body$ DECLARE rec record; BEGIN FOR rec IN ( SELECT * FROM sometable) LOOP RETURN NEXT rec; END LOOP; RETURN; END; $body$ LANGUAGE 'plpgsql' VOLATILE; As you can see, the number and typ

[SQL] function returning result set of varying column

2008-06-02 Thread maria s
Hi friends, I am very new to plsql. I have to write a function that quries few tables and returns a resultset of varying column. In that case I cannot predefine the table with column. If I use RETURNS SETOF then I should know the number of columns and its type?! Is there anyway to return a res