Re: Re: Adding an INTERVAL to a variable

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Re: Adding an INTERVAL to a variable
Date: 2001-08-07 15:38:08
Message-ID: web-97981@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

Attachment Content-Type Size
unknown_filename text/plain 2 bytes
unknown_filename text/plain 2 bytes
unknown_filename text/plain 2 bytes

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2001-08-07 15:38:28 Re: Are circular REFERENCES possible ?
Previous Message Josh Berkus 2001-08-07 15:01:45 Re: Are circular REFERENCES possible ?