Re: Strict-typing benefits/costs - Mailing list pgsql-general

From Tom Lane
Subject Re: Strict-typing benefits/costs
Date
Msg-id 19815.1203177671@sss.pgh.pa.us
Whole thread Raw
In response to Re: Strict-typing benefits/costs  (Michael Glaesemann <grzm@seespotcode.net>)
List pgsql-general
Michael Glaesemann <grzm@seespotcode.net> writes:
> test=# select '2008-02-15' > CURRENT_DATE;

> Here, we're comparing against a date type, so Postgres treats
> '2008-02-15' as a date.

It might be worth pointing out that this is not magic,
but an application of the general rule mentioned at step 2a here:
http://www.postgresql.org/docs/8.3/static/typeconv-oper.html

In any case where Postgres is trying to interpret a binary operator,
and one input has a known type while the other is an unknown-type
literal constant, the preferred interpretation will be that the
constant has the same type as the known-type input.

In a case like 'today is ' || '2008-02-16', *both* inputs are
initially unknown-type literals.  There is a fallback heuristic
that prefers to resolve such cases as type text, which is why
you get text concatenation rather than a "couldn't resolve
operator" error.

In no case does Postgres look at the content of an unknown literal
to determine its type.  '2008-02-16' is not treated differently
from 'foobar'.

            regards, tom lane

pgsql-general by date:

Previous
From: Ken Johanson
Date:
Subject: Re: SELECT CAST(123 AS char) -> 1
Next
From: "Phoenix Kiula"
Date:
Subject: Re: Timestamp indexes (why ">" or "between" does not use index?)