pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: Adding an INTERVAL to a variable
3+ messages / 3 participants
[nested] [flat]
* Re: Adding an INTERVAL to a variable
@ 2001-08-07 15:00 Vivek Khera <khera@kcilink.com>
2001-08-07 15:38 ` Re: Re: Adding an INTERVAL to a variable Josh Berkus <josh@agliodbs.com>
2001-08-09 07:17 ` Re: Adding an INTERVAL to a variable Graham Coates <graham@mindvision.com.au>
0 siblings, 2 replies; 3+ messages in thread
From: Vivek Khera @ 2001-08-07 15:00 UTC (permalink / raw)
To: pgsql-sql
>>>>> "GC" == Graham Coates <graham@mindvision.com.au> writes:
GC> SELECT Invoices.InvoiceDate + INTERVAL '41 Days'
GC> works fine
GC> but when trying to substitute the number of days with a value form a field
GC> e.g.
GC> SELECT Invoices.InvoiceDate + INTERVAL Acct.AverageDaysToPay 'Days'
try
SELECT Invoices.InvoiceDate + Acct.AverageDaysToPay::interval
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D. Khera Communications, Inc.
Internet: khera@kciLink.com Rockville, MD +1-240-453-8497
AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Re: Adding an INTERVAL to a variable
2001-08-07 15:00 Re: Adding an INTERVAL to a variable Vivek Khera <khera@kcilink.com>
@ 2001-08-07 15:38 ` Josh Berkus <josh@agliodbs.com>
1 sibling, 0 replies; 3+ messages in thread
From: Josh Berkus @ 2001-08-07 15:38 UTC (permalink / raw)
To: 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@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Adding an INTERVAL to a variable
2001-08-07 15:00 Re: Adding an INTERVAL to a variable Vivek Khera <khera@kcilink.com>
@ 2001-08-09 07:17 ` Graham Coates <graham@mindvision.com.au>
1 sibling, 0 replies; 3+ messages in thread
From: Graham Coates @ 2001-08-09 07:17 UTC (permalink / raw)
To: pgsql-sql
Thanks for the inspiration Vivek!
Didn't quite work, but when I made it...
dSalesHdrDateDue + (iAcctPayDaysAv || 'Days')::INTERVAL
BINGO! it works.
Happiness is :-)
Graham Coates
"Vivek Khera" <khera@kcilink.com> wrote in message
news:x73d737w54.fsf@onceler.kciLink.com...
> >>>>> "GC" == Graham Coates <graham@mindvision.com.au> writes:
>
> GC> SELECT Invoices.InvoiceDate + INTERVAL '41 Days'
> GC> works fine
> GC> but when trying to substitute the number of days with a value form a
field
> GC> e.g.
>
> GC> SELECT Invoices.InvoiceDate + INTERVAL Acct.AverageDaysToPay 'Days'
>
> try
>
> SELECT Invoices.InvoiceDate + Acct.AverageDaysToPay::interval
>
>
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Vivek Khera, Ph.D. Khera Communications, Inc.
> Internet: khera@kciLink.com Rockville, MD +1-240-453-8497
> AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-08-09 07:17 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-08-07 15:00 Re: Adding an INTERVAL to a variable Vivek Khera <khera@kcilink.com>
2001-08-07 15:38 ` Josh Berkus <josh@agliodbs.com>
2001-08-09 07:17 ` Graham Coates <graham@mindvision.com.au>
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