Re: 9.2 timestamp function syntax error

Поиск
Список
Период
Сортировка
От Guy Rouillier
Тема Re: 9.2 timestamp function syntax error
Дата
Msg-id 5136219F.8000707@gmail.com
обсуждение исходный текст
Ответ на Re: 9.2 timestamp function syntax error  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: 9.2 timestamp function syntax error
Список pgsql-general
On 3/5/2013 9:52 AM, Tom Lane wrote:
> Adrian Klaver <adrian.klaver@gmail.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


В списке pgsql-general по дате отправления:

Предыдущее
От: Maciek Sakrejda
Дата:
Сообщение: Re: [HACKERS] Floating point error
Следующее
От: Alexander Farber
Дата:
Сообщение: Re: Finding matching words in a word game