Re: Planning error in dynamic string creation in plpgsql - Mailing list pgsql-general

From David Johnston
Subject Re: Planning error in dynamic string creation in plpgsql
Date
Msg-id 1389022934339-5785523.post@n5.nabble.com
Whole thread Raw
In response to Re: Planning error in dynamic string creation in plpgsql  (Adrian Klaver <adrian.klaver@gmail.com>)
Responses Re: Planning error in dynamic string creation in plpgsql
Re: Planning error in dynamic string creation in plpgsql
List pgsql-general
Adrian Klaver-3 wrote
>>
>>
>> In the real function I'm writing, the columns to be used in the string
>> being created are pulled from a configuration table, so their types
>> could be anything. So casting the quote_literal() calls is not really an
>> option here.
>>
>> Any help would be appreciated.
>
> Cast before the quote_literal?
>
> Example:
>
> EXECUTE 'SELECT min('||v_col||'::text) as min, max('||v_col||'::text) as
> max FROM test_temp' INTO v_record;

Right idea if the loss of original type in the min/max query is acceptable
(which it should be).  But the cast wants to be of the min/max RESULT not
the min/max INPUT.

SELECT min(' || v_col || ')::text AS min_text, max(' || v_col || ')::text AS
max_text FROM ...

Min/Max logic wants to be done by the rules for the original type, not
according to string collation rules.

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Planning-error-in-dynamic-string-creation-in-plpgsql-tp5785421p5785523.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: WAL archive cleanup om master
Next
From: Stephen Woodbridge
Date:
Subject: Re: Do I have to free storage in a UDF if I raise an error?