Re: [GENERAL] to_timestamp() and quarters

Bruce Momjian <bruce@momjian.us>

From: Bruce Momjian <bruce@momjian.us>
To: Scott Bailey <artacus@comcast.net>
Cc: PostgreSQL-development <pgsql-hackers@postgreSQL.org>
Date: 2010-03-03T03:34:30Z
Lists: pgsql-hackers, pgsql-general

Attachments

Scott Bailey wrote:
> Tom Lane wrote:
> > Asher Hoskins <asher@piceur.co.uk> writes:
> >> I can't seem to get to_timestamp() or to_date() to work with quarters, 
> > 
> > The source code says
> > 
> >                  * We ignore Q when converting to date because it is not
> >                  * normative.
> >                  *
> >                  * We still parse the source string for an integer, but it
> >                  * isn't stored anywhere in 'out'.
> > 
> > That might be a reasonable position, but it seems like it'd be better to
> > throw an error than silently do nothing.  Anybody know what Oracle does
> > with this?
> 
> +1 for throwing error.
> Oracle 10g throws ORA-01820: format code cannot appear in date input format.

Well, I can easily make it do what you expect, and I don't see many
error returns in that area of the code, so I just wrote a patch that
does what you would expect rather than throw an error.

	test=> select to_date('2010-1', 'YYYY-Q');
	  to_date
	------------
	 2010-01-01
	(1 row)
	
	test=> select to_date('2010-3', 'YYYY-Q');
	  to_date
	------------
	 2010-07-01
	(1 row)
	
	test=> select to_date('2010-7', 'YYYY-Q');
	  to_date
	------------
	 2011-07-04
	(1 row)

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  PG East:  http://www.enterprisedb.com/community/nav-pg-east-2010.do