pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: stan <stanb@panix.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Problems with using function input paramaters
Date: Sat, 31 Aug 2019 11:13:30 -0400
Message-ID: <23260.1567264410@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwaEENXNMJy9fbxN8VjAkSrRqgMWMPFma1agLevm0bZ5_Q@mail.gmail.com>
References: <20190831140510.GB23660@panix.com>
	<CAKFQuwaEENXNMJy9fbxN8VjAkSrRqgMWMPFma1agLevm0bZ5_Q@mail.gmail.com>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sat, Aug 31, 2019 at 7:05 AM stan <stanb@panix.com> wrote:
>> CURRENT_DATE) - interval '  $1
>> month - 1
>> ' day as date)

> ($1 || ' month')::interval  -- should work

FWIW, I tend to prefer doing it with interval arithmetic, like this:

$1 * '1 month'::interval - '1 day'::interval

It's faster (not enormously so, but measurably) thanks to not having
to construct and then parse a text string.  To my mind it's easier
to reason about, too, and a bit safer.

			regards, tom lane





view thread (4+ messages)

Message-ID: <23260.1567264410@sss.pgh.pa.us>
Permalink:  ../23260.1567264410@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23260.1567264410@sss.pgh.pa.us

 · 

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, stanb@panix.com
  Subject: Re: Problems with using function input paramaters
  In-Reply-To: <23260.1567264410@sss.pgh.pa.us>
  References: <20190831140510.GB23660@panix.com> <CAKFQuwaEENXNMJy9fbxN8VjAkSrRqgMWMPFma1agLevm0bZ5_Q@mail.gmail.com> <23260.1567264410@sss.pgh.pa.us>

* 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