Thread: plpgsql out parameter with select into
Hi! My question is, how can I get the out parameter from a function with SELECT INTO by name? I mean: create function testfunc1(OUT _status integer) returns integer as $BODY$_status := 0; $BODY$ language plpgsql; create function testfunc2() as declarestatus integer; $BODY$select into status * from testfunc1(); $BODY$ language plpgsql; create function testfunc3() as declarestatus integer; $BODY$select into status _status from testfunc1(); $BODY$ language plpgsql; testfunc2 works, testfunc3 not. Thanks in advance: Imre Horvath
Hi, SELECT column_name INTO var_name FROM ... 2010/8/17 Horváth Imre <horvath.imre@blemidon.hu>: > Hi! > > My question is, how can I get the out parameter from a function with > SELECT INTO by name? > I mean: > > create function testfunc1(OUT _status integer) returns integer as > $BODY$ > _status := 0; > $BODY$ > language plpgsql; > > create function testfunc2() as > declare > status integer; > $BODY$ > select into status * from testfunc1(); > $BODY$ > language plpgsql; > > create function testfunc3() as > declare > status integer; > $BODY$ > select into status _status from testfunc1(); > $BODY$ > language plpgsql; > > testfunc2 works, testfunc3 not. > > Thanks in advance: > Imre Horvath > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > -- Sergey Konoplev Blog: http://gray-hemp.blogspot.com / Linkedin: http://ru.linkedin.com/in/grayhemp / JID/GTalk: gray.ru@gmail.com / Skype: gray-hemp / ICQ: 29353802
It don't work... Only select into status * from... works. Imre Horvath 2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta: > Hi, > > SELECT column_name > INTO var_name > FROM ... > > 2010/8/17 Horváth Imre <horvath.imre@blemidon.hu>: > > Hi! > > > > My question is, how can I get the out parameter from a function with > > SELECT INTO by name? > > I mean: > > > > create function testfunc1(OUT _status integer) returns integer as > > $BODY$ > > _status := 0; > > $BODY$ > > language plpgsql; > > > > create function testfunc2() as > > declare > > status integer; > > $BODY$ > > select into status * from testfunc1(); > > $BODY$ > > language plpgsql; > > > > create function testfunc3() as > > declare > > status integer; > > $BODY$ > > select into status _status from testfunc1(); > > $BODY$ > > language plpgsql; > > > > testfunc2 works, testfunc3 not. > > > > Thanks in advance: > > Imre Horvath > > > > > > -- > > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > > To make changes to your subscription: > > http://www.postgresql.org/mailpref/pgsql-sql > > > > >
It don't work... Only select into status * from... works. Imre Horvath 2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta: > Hi, > > SELECT column_name > INTO var_name > FROM ... > > 2010/8/17 Horváth Imre <horvath.imre@blemidon.hu>: > > Hi! > > > > My question is, how can I get the out parameter from a function with > > SELECT INTO by name? > > I mean: > > > > create function testfunc1(OUT _status integer) returns integer as > > $BODY$ > > _status := 0; > > $BODY$ > > language plpgsql; > > > > create function testfunc2() as > > declare > > status integer; > > $BODY$ > > select into status * from testfunc1(); > > $BODY$ > > language plpgsql; > > > > create function testfunc3() as > > declare > > status integer; > > $BODY$ > > select into status _status from testfunc1(); > > $BODY$ > > language plpgsql; > > > > testfunc2 works, testfunc3 not. > > > > Thanks in advance: > > Imre Horvath > > > > > > -- > > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > > To make changes to your subscription: > > http://www.postgresql.org/mailpref/pgsql-sql > > > > >
What is your PG version? 2010/8/18 Horváth Imre <horvath.imre@blemidon.hu>: > It don't work... > > Only select into status * from... works. > > Imre Horvath > > 2010. 08. 18, szerda keltezéssel 09.42-kor Sergey Konoplev ezt írta: >> Hi, >> >> SELECT column_name >> INTO var_name >> FROM ... >> >> 2010/8/17 Horváth Imre <horvath.imre@blemidon.hu>: >> > Hi! >> > >> > My question is, how can I get the out parameter from a function with >> > SELECT INTO by name? >> > I mean: >> > >> > create function testfunc1(OUT _status integer) returns integer as >> > $BODY$ >> > _status := 0; >> > $BODY$ >> > language plpgsql; >> > >> > create function testfunc2() as >> > declare >> > status integer; >> > $BODY$ >> > select into status * from testfunc1(); >> > $BODY$ >> > language plpgsql; >> > >> > create function testfunc3() as >> > declare >> > status integer; >> > $BODY$ >> > select into status _status from testfunc1(); >> > $BODY$ >> > language plpgsql; >> > >> > testfunc2 works, testfunc3 not. >> > >> > Thanks in advance: >> > Imre Horvath >> > >> > >> > -- >> > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) >> > To make changes to your subscription: >> > http://www.postgresql.org/mailpref/pgsql-sql >> > >> >> >> > > > -- Sergey Konoplev Blog: http://gray-hemp.blogspot.com / Linkedin: http://ru.linkedin.com/in/grayhemp / JID/GTalk: gray.ru@gmail.com / Skype: gray-hemp / ICQ: 29353802
> 2010/8/18 Horv�th Imre <horvath.imre@blemidon.hu>: >> It don't work... A function returning a scalar type cannot control the column name assigned to the scalar in the calling query. To do that, you need to return a composite type, which means there need to be at least two OUT parameters if you're trying to do it via OUT-parameter names. regards, tom lane
2010/8/19 Tom Lane <tgl@sss.pgh.pa.us>: >> 2010/8/18 Horváth Imre <horvath.imre@blemidon.hu>: >>> It don't work... > > A function returning a scalar type cannot control the column name > assigned to the scalar in the calling query. To do that, you need to > return a composite type, which means there need to be at least two OUT > parameters if you're trying to do it via OUT-parameter names. So we could do either SELECT funcname INTO varname FROM funcname() or SELECT * INTO varname FROM funcname(); or SELECT funcname() INTO varname correct? > > regards, tom lane > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > -- Sergey Konoplev Blog: http://gray-hemp.blogspot.com / Linkedin: http://ru.linkedin.com/in/grayhemp / JID/GTalk: gray.ru@gmail.com / Skype: gray-hemp / ICQ: 29353802