Re: BUG #5225: create table: cast necessary for constant??

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Kurt Wagner" <kurt(dot)wagnerextern(at)leoni(dot)com>,<tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-bugs(at)postgresql(dot)org>,<craig(at)postnewspapers(dot)com(dot)au>
Subject: Re: BUG #5225: create table: cast necessary for constant??
Date: 2009-12-03 14:57:00
Message-ID: 4B177D5C020000250002D02A@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Wagner, Kurt" <kurt(dot)wagnerextern(at)leoni(dot)com> wrote:

> when writing a character constant elsewhere
> then at first it is interpreted as character constant - right?
> then it is casted to the desired type

No. It was confusing for me, too; but the PostgreSQL behavior is to
treat what the standard calls a <character string literal> as being
of type UNKNOWN -- just like the behavior described in the spec for
NULL. When it is used in some context where the type must be
resolved, it then tries to pick an appropriate type. (I believe
there is some slight preference for type TEXT when there are
multiple possibilities.) This is helpful for those wanting to use
literals of non-standard types. (Many people use PostgreSQL
specifically because of the ability to define custom types and
operators.)

There is an understandable tendency of those who work deep in the
guts of the PostgreSQL software, making all this custom type code
work, that those coming into PostgreSQL from other environments come
with the assumption that these literals will be treated as character
strings. From their perspective there is nothing more natural than
to view such a literal as lacking any type information, with the
obvious implication that you should explicitly give it a type.

Once you shake out any problems from code you are migrating, you'll
find it's not hard to write new code in a way which will work in
either environment.

-Kevin

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kevin Grittner 2009-12-03 15:02:49 Re: BUG #5225: create table: cast necessary for constant??
Previous Message Kevin Grittner 2009-12-03 14:46:20 Re: BUG #5225: create table: cast necessary for constant??