Re: Order by parameter inside pgsql function ignored

From: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Order by parameter inside pgsql function ignored
Date: 2009-06-02 08:20:21
Message-ID: 200906021020.21328.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Leif B. Kristensen 2009-06-02 08:45:27 Re: Order by parameter inside pgsql function ignored
Previous Message Anton Marchenkov 2009-06-02 07:38:56 Order by parameter inside pgsql function ignored