Re: String literal doesn't autocast to text type

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: String literal doesn't autocast to text type
Дата
Msg-id CAKFQuwZFPrCh6sWDStfdwu_LaBf_XA8mwcznkS4hsdywiYedyQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: String literal doesn't autocast to text type  (Melvin Davidson <melvin6925@gmail.com>)
Ответы Re: String literal doesn't autocast to text type  (Alex Ignatov <a.ignatov@postgrespro.ru>)
Список 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.ignatov@postgrespro.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@gmail.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); 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.
 

В списке pgsql-general по дате отправления:

Предыдущее
От: Alex Ignatov
Дата:
Сообщение: Re: String literal doesn't autocast to text type
Следующее
От: Francisco Olarte
Дата:
Сообщение: Re: multiple UNIQUE indices for FK