pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Ray <rray@mstc.state.ms.us>
To: pgsql-sql@postgresql.org
Subject: Re: Help with quotes in plpgsql
Date: Wed, 20 Dec 2006 08:10:53 -0600 (CST)
Message-ID: <Pine.LNX.4.64.0612200800160.24340@rray.drdc.mstc.ms.gov> (raw)
In-Reply-To: <14125.1166574420@sss.pgh.pa.us>
References: <8C5B026B51B6854CBE88121DBF097A866A4982@ehost010-33.exch010.intermedia.net>
	<14125.1166574420@sss.pgh.pa.us>

It makes sense when ya'll explain it
It never sounds that good when I'm talkin to myself
That solves my problem but not my ignorance
I'm still curious about how would I properly quote

create or replace function test(integer) returns setof text as $$
declare
   a record;
begin
   select into a now() - interval '$1 day';
   return next a;
   return;
end
$$ language 'plpgsql';

I got the usage example for interval from 
http://www.postgresql.org/docs/8.1/interactive/functions-datetime.html

Thanks
Richard


On Tue, 19 Dec 2006, Tom Lane wrote:

> "Hector Villarreal" <HVillarreal@mynewplace.com> writes:
>>    select into a now() - ($1::text||'days')::interval;
>
> People keep suggesting variants of that as ways to convert numeric
> values to intervals, but it's really extremely bad practice.  Much
> better is to use number-times-interval multiplication:
>
>     select into a now() - $1 * '1 day'::interval;
>
> This is less typing, at least as easy to understand, more flexible
> (you can use any scale factor you want), and considerably more
> efficient.  The first way involves coercing the integer to text,
> then text-concatenating that with a constant, then applying
> interval_in which does a fairly nontrivial parsing process.
> The second way is basically just a multiplication, because
> '1 day'::interval is already a constant value of type interval.
>
> 			regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
>                http://www.postgresql.org/about/donate
>



view thread (11+ messages)  latest in thread

Message-ID: <Pine.LNX.4.64.0612200800160.24340@rray.drdc.mstc.ms.gov>
Permalink:  ../Pine.LNX.4.64.0612200800160.24340@rray.drdc.mstc.ms.gov/
Also on:    postgresql.org/message-id/Pine.LNX.4.64.0612200800160.24340@rray.drdc.mstc.ms.gov

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: rray@mstc.state.ms.us
  Subject: Re: Help with quotes in plpgsql
  In-Reply-To: <Pine.LNX.4.64.0612200800160.24340@rray.drdc.mstc.ms.gov>
  References: <8C5B026B51B6854CBE88121DBF097A866A4982@ehost010-33.exch010.intermedia.net> <14125.1166574420@sss.pgh.pa.us> <Pine.LNX.4.64.0612200800160.24340@rray.drdc.mstc.ms.gov>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox