Re: Default conversion of type numeric to text in 7.1.3

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Default conversion of type numeric to text in 7.1.3
Дата
Msg-id 25088.1006373344@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Default conversion of type numeric to text in 7.1.3  ("Gurunandan R. Bhat" <grbhat@exocore.com>)
Ответы Re: Default conversion of type numeric to text in 7.1.3  ("Gurunandan R. Bhat" <grbhat@exocore.com>)
Список pgsql-general
"Gurunandan R. Bhat" <grbhat@exocore.com> writes:
>     The excellently detailed Postgres manual, seems to indicate that
> the concatenation operator "||"  converts the right and left operands of
> all base types to text with the exception of boolean which cannot be cast
> as any other type.

Uh, where did you get that impression?  || is a string operator only
(and maybe a bit string and bytea operator, depending on which release
you are using).

There are implicit coercions to text for some datatypes.  It's my
feeling that such implicit coercions are dangerous, and that we ought
to avoid them rather than add more.  Too many implicit coercion paths,
and you'll never be sure what a multi-datatype expression is going to
be interpreted to do.

> Also, what
> special problems prevent the conversion of boolean to text?

None other than no one having got round to it.  Again, though, I'd not
like to see such a conversion occur implicitly.  Example:

regression=# select true || false;
ERROR:  Unable to identify an operator '||' for types 'boolean' and 'boolean'
        You will have to retype this query using an explicit cast

regression=# create function text(boolean) returns text as '
regression'# select case when $1 then ''true'' else ''false'' end
regression'# ' language 'sql';
CREATE

regression=# select true || false;
 ?column?
-----------
 truefalse
(1 row)

IMHO this is not good; I should have needed to write

regression=# select text(true) || text(false);
 ?column?
-----------
 truefalse
(1 row)

to make it clear what I wanted.

            regards, tom lane

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

Предыдущее
От: Stuart Robinson
Дата:
Сообщение: Re: PG vs MySQL
Следующее
От: "Ben-Nes Michael"
Дата:
Сообщение: Re: PG vs MySQL