Search Postgresql Archives

Re: 9.2 timestamp function syntax error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/5/2013 9:52 AM, Tom Lane wrote:
Adrian Klaver <adrian.klaver@xxxxxxxxx> 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


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux