Re: help on quoteing in plpgsql function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Treat <rtreat(at)webmd(dot)net>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: help on quoteing in plpgsql function
Date: 2002-06-18 13:36:16
Message-ID: 25662.1024407376@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Robert Treat <rtreat(at)webmd(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2002-06-18 13:38:36 Re: Monitoring postgres slowdowns
Previous Message terry 2002-06-18 13:25:17 Re: Input/Output Error Message