From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Michael Glaesemann <grzm(at)seespotcode(dot)net> |
Cc: | Ken Johanson <pg-user(at)kensystem(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Strict-typing benefits/costs |
Date: | 2008-02-16 16:01:11 |
Message-ID: | 19815.1203177671@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Michael Glaesemann <grzm(at)seespotcode(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Phoenix Kiula | 2008-02-16 16:13:32 | Re: Timestamp indexes (why ">" or "between" does not use index?) |
Previous Message | Ken Johanson | 2008-02-16 15:57:40 | Re: SELECT CAST(123 AS char) -> 1 |