Re: help on quoteing in plpgsql function - Mailing list pgsql-general

From Tom Lane
Subject Re: help on quoteing in plpgsql function
Date
Msg-id 25662.1024407376@sss.pgh.pa.us
Whole thread Raw
In response to Re: help on quoteing in plpgsql function  (Robert Treat <rtreat@webmd.net>)
List pgsql-general
Robert Treat <rtreat@webmd.net> writes:
>         strDelete := ''DELETE FROM ''
>             || quote_ident(arrTables.table_name)
>             || '' WHERE timestamp < now() - ((''''''
>             || arrTables.historysize
>             || '' days'''' )::interval) '';
>         EXECUTE strDelete;

> Note that no "quote_foo" function was needed on the second variable
> since I had to enclose it along with other text within my own quotes.

Seems like it'd be better to use quote_literal, viz

        strDelete := ''DELETE FROM ''
            || quote_ident(arrTables.table_name)
            || '' WHERE timestamp < now() - ''
            || quote_literal(arrTables.historysize || '' days'')
            || ''::interval'';
        EXECUTE strDelete;

            regards, tom lane

pgsql-general by date:

Previous
From: terry@greatgulfhomes.com
Date:
Subject: Re: Input/Output Error Message
Next
From: Fabricio Boppre
Date:
Subject: number of registers of a table