Bug or feature? Timestamp parsing

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Bug or feature? Timestamp parsing
Date: 2010-06-09 23:05:59
Message-ID: 4C101E57.1020805@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


select 'NOW?'::TIMESTAMP;
timestamp
----------------------------
2010-06-09 14:08:21.020259

postgres=# select ';;;infinity???#(at)$%$'::TIMESTAMP;
timestamp
-----------
infinity
(1 row)

It appears that the ts parser will ignore any punctuation surrounding
the special value calls.

In general, this isn't a potential problem. However, it could cause
some confusion with careless value replacement by users. Imagine a case
like this:

create or replace function epoch(integer) returns timestamp language sql
as 'SELECT ''epoch''::timestamp + $1 * interval ''1 second'';';

Then later you fail on your client quoting rules and do the following in
your app code:

UPDATE some_table
SET timestamp_field = 'epoch(150000)'
WHERE id = 501;

The above will result in 1970-01-01 00:00:00 UTC getting into the field,
not 1970-01-02 17:40:00 as the user intended, since the '(150000)' will
be ignored. And given the lack of an error message, a lot of debugging
time.

On the other hand, it appears that our timestamps have had this bug
since at least 8.0, so it clearly isn't a widespread problem for most
users. And likely some users have been "taking advantage" of letting
garbage into their timestamp casts, so there would be some application
breakage.

Thoughts?

--
-- Josh Berkus
PostgreSQL Experts Inc.
http://www.pgexperts.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2010-06-09 23:19:26 Re: hot_standby = on
Previous Message Simon Riggs 2010-06-09 22:52:31 Re: Keepalive for max_standby_delay