From: Josh Berkus <josh@agliodbs.com>
To: pgsql-sql@postgresql.org
Subject: Re: Re: Adding an INTERVAL to a variable
Date: Tue, 07 Aug 2001 08:38:08 -0700
Message-ID: <web-97981@davinci.ethosmedia.com> (raw)
In-Reply-To: <x73d737w54.fsf@onceler.kciLink.com>
Graham,
> GC> SELECT Invoices.InvoiceDate + INTERVAL Acct.AverageDaysToPay
> 'Days'
Actually, all you're missing is some punctuation. Don't skimp on the ::
and () ! Plus, you should use explicit CASTs wherever you remember
them:
SELECT Invoices.InvoiceDate + INTERVAL(CAST(Acct.AverageDaysToPay AS
VARCHAR) || ' days');
Will work fine. Here I've explicitly cast the Average Days integer (if
it's NUMERIC or FLOAT, you will have to use TO_CHAR()) to varchar, then
concatinated it with the word "days". *Then* I convert it to INTERVAL,
which will recognize '# days' as a valid expression.
IMHO, you've been lucky being able to skip the parens and CASTs so far;
get used to using them.
-Josh
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com
Subject: Re: Re: Adding an INTERVAL to a variable
In-Reply-To: <web-97981@davinci.ethosmedia.com>
* 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