Re: BUG #5225: create table: cast necessary for constant?? - Mailing list pgsql-bugs

From Kevin Grittner
Subject Re: BUG #5225: create table: cast necessary for constant??
Date
Msg-id 4B177D5C020000250002D02A@gw.wicourts.gov
Whole thread Raw
In response to Re: BUG #5225: create table: cast necessary for constant??  ("Wagner, Kurt" <kurt.wagnerextern@leoni.com>)
Responses Re: BUG #5225: create table: cast necessary for constant??  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
List pgsql-bugs
"Wagner, Kurt" <kurt.wagnerextern@leoni.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

pgsql-bugs by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: BUG #5225: create table: cast necessary for constant??
Next
From: "Kevin Grittner"
Date:
Subject: Re: BUG #5225: create table: cast necessary for constant??