Re: Querying now() - Mailing list pgsql-novice

From Michael Glaesemann
Subject Re: Querying now()
Date
Msg-id 1B15B3D8-5222-11D9-93E5-000A95C88220@myrealbox.com
Whole thread Raw
In response to Querying now()  (A Gilmore <agilmore@shaw.ca>)
List pgsql-novice
On Dec 20, 2004, at 9:05, A Gilmore wrote:

> Id like my application to do something like this :
>
> SELECT now() AS currentTime WHERE currentTime < '$timestamp';
>
> So if it returns a row Id know $timestamp is not in the past.  However
> when you run this it simply says 'ERROR:  column "currentTime" does
> not exist'.

AFAIK, SELECT clause aliases are not available to any other part of the
query: it's looking for a column called currentTime, but there isn't
one in the FROM clause tables. Then again, you don't even have a FROM
clause. :) In general, it's best to show the exact query you're trying
and the error messages you're getting--and if possible, reduce it to a
test case that still exhibits the problem.

You probably want something like:

SELECT foo FROM bar WHERE current_timestamp < baz;

( current_timestamp is the SQL standard spelling of the PostgreSQL
alternative now(). )

Also note that all identifiers are converted to lowercase unless
double-quoted. PostgreSQL sees currentTime as currenttime.

Hope this helps.


Michael Glaesemann
grzm myrealbox com


pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Querying now()
Next
From: A Gilmore
Date:
Subject: Re: Querying now()