BUG #1309: PL/PGSQL function: ORDER BY does not accept variables

From: "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1309: PL/PGSQL function: ORDER BY does not accept variables
Date: 2004-11-09 22:15:10
Message-ID: 20041109221510.A80C973A164@www.postgresql.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 1309
Logged by: Christina Zhang

Email address: czhang(at)theinformationforge(dot)com

PostgreSQL version: 7.4.1

Operating system: Linux

Description: PL/PGSQL function: ORDER BY does not accept variables

Details:

When we write a function using PL/PGSQL:

CREATE OR REPLACE FUNCTION uf_TestSearch(integer,varchar)RETURNS setof
ut_TestSearch
AS
'
DECLARE
v_MyRow ut_TestSearch%rowtype;
a_OrderBy ALIAS FOR $1;
a_SortAsc ALIAS FOR $2;
BEGIN
FOR v_MyRow IN
SELECT Colum1,
Column2,
Column3
FROM Table1
ORDER BY a_OrderBy a_SortAsc
LOOP
RETURN NEXT v_MyRow;
END LOOP;
RETURN;

RETURN;

END;
'LANGUAGE 'plpgsql';

Problem: When I use PERFORM uf_TestSearch(1,'ASC');
The returned result set are always sorted by "Column2", no matter what is
passed in the first parameter.

Could you please check whether the ORDER BY works correctly or not?

Thank you,

Christina

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-11-09 22:48:15 Re: BUG #1309: PL/PGSQL function: ORDER BY does not accept variables
Previous Message Kris Jurka 2004-11-09 21:39:26 Re: BUG #1308: Bug with JDBC driver on duplicate