Re: 9.2 timestamp function syntax error

From: Guy Rouillier <guy(dot)rouillier(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: 9.2 timestamp function syntax error
Date: 2013-03-05 16:47:27
Message-ID: 5136219F.8000707@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/5/2013 9:52 AM, Tom Lane wrote:
> Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> writes:
>> This does not work:
>
>> test=> select timestamp(now()::timestampz);
>> ERROR: syntax error at or near "now"
>
> timestamp(something) is a type name. Per the comment in gram.y:
>
> * The type names appearing here are not usable as function names
> * because they can be followed by '(' in typename productions, which
> * looks too much like a function call for an LR(1) parser.

In PgAdmin, here is how timestamp() is defined:

CREATE OR REPLACE FUNCTION "timestamp"(timestamp with time zone)
RETURNS timestamp without time zone AS
'timestamptz_timestamp'
LANGUAGE internal STABLE STRICT
COST 1;
ALTER FUNCTION "timestamp"(timestamp with time zone)
OWNER TO postgres;
COMMENT ON FUNCTION "timestamp"(timestamp with time zone) IS 'convert
timestamp with time zone to timestamp';

and here is now timestamptz() is defined:

CREATE OR REPLACE FUNCTION timestamptz(timestamp without time zone)
RETURNS timestamp with time zone AS
'timestamp_timestamptz'
LANGUAGE internal STABLE STRICT
COST 1;
ALTER FUNCTION timestamptz(timestamp without time zone)
OWNER TO postgres;
COMMENT ON FUNCTION timestamptz(timestamp without time zone) IS 'convert
timestamp to timestamp with time zone';

Ugh, I just noticed the quotation marks around the timestamp function.
This works:

select "timestamp"(now()::timestamptz); => timestamp without time zone

This is a subtlety bound to be lost on most. Why is there both a
function and a type name with the same name? I suppose I could define a
synonym to make the function name distinct, but this seems like
something that should be addressed.

Thanks.

--
Guy Rouillier

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2013-03-05 16:52:58 Re: Finding matching words in a word game
Previous Message Maciek Sakrejda 2013-03-05 16:37:58 Re: [HACKERS] Floating point error