Re: String literal doesn't autocast to text type

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Melvin Davidson <melvin6925(at)gmail(dot)com>
Cc: Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: String literal doesn't autocast to text type
Date: 2016-03-04 17:59:02
Message-ID: CAKFQuwZFPrCh6sWDStfdwu_LaBf_XA8mwcznkS4hsdywiYedyQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

It would be nice if you'd follow the list convention of bottom-posting.
Not doing that is much more annoying than the omission of version and o/s -
especially the later since PostgreSQL purports to be generally o/s agnostic.

On Fri, Mar 4, 2016 at 12:17 PM, Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>
> wrote:
>
>> Hello!
>> Why string literal like 'Hello world!' doesnt automagicaly cast to text
>> type?
>>
>>
>> But why we don't have this type cast by default in Postgres? Is there any
>> fundamental restriction on that or there is some reasons for that?
>>
>>
On Friday, March 4, 2016, Melvin Davidson <melvin6925(at)gmail(dot)com> wrote:

> Probably because pg_typeof() returns the OID of a COLUMN in a table def..
> Strings literals do not have oid's.
>
> http://www.postgresql.org/docs/9.4/interactive/functions-info.html
>
> "pg_typeof returns the OID of the data type of the value that is passed
> to it. This can be helpful for troubleshooting or dynamically constructing
> SQL queries. The function is declared as returning regtype, which is an
> OID alias type (see Section 8.18
> <http://www.postgresql.org/docs/9.4/interactive/datatype-oid.html>); this
> means that it is the same as an OID for comparison purposes but displays as
> a type name. For example:"
>

While true this doesn't actually answer the question - that being what's
the motiviation for not implicitly casting away from unknown. I suspect
that the main reason is that in an extensible system like PostgreSQL it is
deemed risky to have too many implicit casts. Having one from unknown
required the system to make decisions that could result in unexpected
results that would be hard to catch without careful review of queries and
results. It is an issue of some contention in the community but so far no
one has convinced the committees to change how this works.

> Please in the future, ALWAYS specify your PostgreSQL version and O/S,
> regardless of whether or not you thinnk it is pertinent.
>

But don't feel too bad if you forget...

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Olarte 2016-03-04 17:59:46 Re: multiple UNIQUE indices for FK
Previous Message Alex Ignatov 2016-03-04 17:55:32 Re: String literal doesn't autocast to text type