Re: Default conversion of type numeric to text in 7.1.3 - Mailing list pgsql-general

From Tom Lane
Subject Re: Default conversion of type numeric to text in 7.1.3
Date
Msg-id 25088.1006373344@sss.pgh.pa.us
Whole thread Raw
In response to Default conversion of type numeric to text in 7.1.3  ("Gurunandan R. Bhat" <grbhat@exocore.com>)
Responses Re: Default conversion of type numeric to text in 7.1.3
List 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 by date:

Previous
From: Stuart Robinson
Date:
Subject: Re: PG vs MySQL
Next
From: "Ben-Nes Michael"
Date:
Subject: Re: PG vs MySQL