Re: Unexpected parse behaviour for date to timestamp

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unexpected parse behaviour for date to timestamp
Date: 2003-03-08 04:48:50
Message-ID: 3712.1047098930@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp> writes:
> As an aside, and for my own edificaton, what is the "correct" was to
> pass a date in as an SQL argument? Using '2003-01-01' works but it seems
> the parser is actually viewing this as text and not a date?

No. That is actually the preferred way to do it. A literal encased in
single quotes is not text to Postgres --- it is an untyped literal that
will be cast automatically to the datatype needed by its context. In
particular, given an expression like
columnref operator 'literal'
the untyped literal will preferentially be cast to the same datatype as
the column reference. (I believe the parser will explore other possible
interpretations if that one doesn't match any available operator, but
that will definitely be what's chosen if there's a matching operator.)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua Moore-Oliva 2003-03-08 06:11:13 Define maximum time increment.
Previous Message Jean-Christian Imbeault 2003-03-08 04:33:44 Re: Unexpected parse behaviour for date to timestamp