Re: Unexpected parse behaviour for date to timestamp - Mailing list pgsql-general

From Tom Lane
Subject Re: Unexpected parse behaviour for date to timestamp
Date
Msg-id 3712.1047098930@sss.pgh.pa.us
Whole thread Raw
In response to Re: Unexpected parse behaviour for date to timestamp  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
List pgsql-general
Jean-Christian Imbeault <jc@mega-bucks.co.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

pgsql-general by date:

Previous
From: Jean-Christian Imbeault
Date:
Subject: Re: Unexpected parse behaviour for date to timestamp
Next
From: Joshua Moore-Oliva
Date:
Subject: Define maximum time increment.