Re: Dynamic expressions set in "order by" clause

From: Erik Jones <erik(at)myemma(dot)com>
To: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dynamic expressions set in "order by" clause
Date: 2007-11-21 16:43:37
Message-ID: 7DB0E8D0-A749-4D0E-A852-7FA3BB61DA83@myemma.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Nov 21, 2007, at 9:48 AM, Sergey Konoplev wrote:

> Hello,
>
> I have a procedure which takes few arguments. The arguments must
> affect expressions set of "order by" clause. For instance in one case
> ordering must be performed by 1st, 2nd (desc) and 3rd fields but in
> another by 3rd, 1st and 2nd fields.
>
> Is there a way to manage it without using dynamic queries (execute
> '...') and code duplicating?
>
> --
> Regards,
> Sergey Konoplev

Not that I've ever heard of. Well, you move the procedure up into
the application level but inside the database you'll need a procedure
to handle the branching on the argument values with each branch
either running a mostly duplicated query (the only difference in the
order by) or each branch generating the order by expression as a
string which you then use in an EXECUTE statement. If anyone knows
different, I'd love to hear it.

Erik Jones

Software Developer | Emma®
erik(at)myemma(dot)com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-11-21 16:49:25 Re: loading a funtion script from a file
Previous Message Gauthier, Dave 2007-11-21 16:41:25 Re: loading a funtion script from a file