From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | chestie <mcit(at)argus(dot)net(dot)au> |
Cc: | Wil Duis <Wil(dot)Duis(at)asml(dot)com>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Calculation error |
Date: | 2003-06-05 03:17:25 |
Message-ID: | 29118.1054783045@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
chestie <mcit(at)argus(dot)net(dot)au> writes:
> I kept getting this same error, heres what I was trying to do.
> it := select int4(extract(epoch from timestamp $1 -
> extract(epoch from timestamp $2));
You should just write
it := select int4(extract(epoch from $1) -
extract(epoch from $2));
You are confusing the syntax
timestamp 'string literal'
(or more generally, any type name followed by a string literal) with
something that you should apply to a non-constant value. That syntax
works *only* for literal constants.
In your example, $1 and $2 are already of type timestamp and require
no further conversion, so the extract()s will work fine as I show above.
If you did need a run-time type conversion, you'd have to write
"CAST($1 AS timestamp)" (the SQL-spec-approved syntax) or
"$1::timestamp" (Postgres' traditional notation).
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-06-05 04:00:33 | Re: Updatable view does not work [oops, quite long!] |
Previous Message | chestie | 2003-06-05 02:28:27 | Re: Calculation error |