BUG #1309: PL/PGSQL function: ORDER BY does not accept variables - Mailing list pgsql-bugs

From PostgreSQL Bugs List
Subject BUG #1309: PL/PGSQL function: ORDER BY does not accept variables
Date
Msg-id 20041109221510.A80C973A164@www.postgresql.com
Whole thread Raw
Responses Re: BUG #1309: PL/PGSQL function: ORDER BY does not accept variables
List pgsql-bugs
The following bug has been logged online:

Bug reference:      1309
Logged by:          Christina Zhang

Email address:      czhang@theinformationforge.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

pgsql-bugs by date:

Previous
From: Kris Jurka
Date:
Subject: Re: BUG #1308: Bug with JDBC driver on duplicate
Next
From: Tom Lane
Date:
Subject: Re: BUG #1309: PL/PGSQL function: ORDER BY does not accept variables