On Tuesday 2. June 2009, Anton Marchenkov wrote: >Hi! > >I'm trying to use the order by parameter inside a function, but it is >ignored. Any ideas why? And how can I sort by external parameters > inside pgsql function? What's the problem with SELECT * FROM foo(myvar) ORDER BY sort_key ASC ? If sort_key is the name of a column, you must use EXECUTE and build a dynamic query string like: FOR rec IN EXECUTE 'SELECT * FROM customers.customers_with_mark_deleted c ORDER BY ' || sort_key || ' ASC' -- Leif Biberg Kristensen | Registered Linux User #338009 Me And My Database: http://solumslekt.org/blog/ -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general