![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
"Roy Wood" <roy.wood (AT) clearswift (DOT) com> writes: Description: ERROR: RETURN cannot have a parameter in function returning void at or near "NULL" at character 148 Obtained this error creating a Function which contained 'RETURN NULL;' on the new 8.1-beta2 The complaint seems valid to me... regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
#2
| |||
| |||
|
|
hi, I am trying to create a stored procedure that takes a column name as parameter and then uses it to sort the table for result set. |
C.
#3
| |||
| |||
|
|
hi, =20 I am trying to create a stored procedure that takes a column name as parameter and then uses it to sort the table for result set. =20 create or replace function ptest_Sort_Select(varchar) returns setof ptest1 as $$ DECLARE res ptest1%ROWTYPE; BEGIN for res in select * from ptest1 order by ptest1.$1 asc loop return next res; end loop; return; END; $$ language plpgsql strict; |
|
but the output was not sorted. =20 Then i tried this stored procedure: create or replace function test(varchar) returns int as $$ DECLARE res int; BEGIN res:=3D0; raise notice 'select * from ptest1 order by $1 asc'; |
#4
| |||||
| |||||
|
|
On Wed, Sep 28, 2005 at 12:25:54PM -0700, vishal saberwal wrote: hi, I am trying to create a stored procedure that takes a column name as parameter and then uses it to sort the table for result set. create or replace function ptest_Sort_Select(varchar) returns setof ptest1 as $$ DECLARE res ptest1%ROWTYPE; BEGIN for res in select * from ptest1 order by ptest1.$1 asc loop return next res; end loop; return; END; $$ language plpgsql strict; But you might try ... for res in execute 'select * from ptest1 order by ' || $1 || ' asc' loop ... i.e. build up the query string and run with execute. but the output was not sorted. Then i tried this stored procedure: create or replace function test(varchar) returns int as $$ DECLARE res int; BEGIN res:=3D0; raise notice 'select * from ptest1 order by $1 asc'; I don't think plpgsql expands variables within strings. You'll have to concatenate yourself, like so: raise notice 'select * from ptest1 order by ' || $1 || ' asc'; HTH -- tomas -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFDO4EaBcgs9XrR2kYRAsy5AJ9J4a1cwY10mVriwvWVY/zdL30CKwCfWdgw rU3My3azyCCT8AG5iMIGXpk=3D =3D/8Tn -----END PGP SIGNATURE----- |
| br |
|
END;<br>> $$ language plpgsql strict;<br><br>But you might try<br>= ...<br> for res in execute 'select * from ptest1 o= |
|
Version: GnuPG v1.2.5 (GNU/Linux)<br><br>iD8DBQFDO4EaBcgs9XrR2kYRAsy5AJ9J4= a1cwY10mVriwvWVY/zdL30CKwCfWdgw |
|
br><br></blockquote></div><br |
![]() |
| Thread Tools | |
| Display Modes | |
| |