Re: Implicit type conversion -- where documented?

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: Kirk Parker <khp(at)equatoria(dot)us>
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Implicit type conversion -- where documented?
Date: 2022-11-11 03:09:31
Message-ID: 20221111030931.434rwnm3rh3htpdj@jrouhaud
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

Hi,

On Thu, Nov 10, 2022 at 06:27:21PM -0800, Kirk Parker wrote:
> I came across what seems like anomalous behavior regarding
> implicit conversion from a numeric type to text. You can write:
>
> select 3.1416 || '?';
>
> and the number implicitly converts to text and concatenates just fine, but
> writing:
>
> select trim(3.1416);
>
> fails with an error message. This seems odd to me--in both cases a float
> literal is used in a context expecting text; in one case it implicitly
> converts, in the other it doesn't.
>
> *This brings up my real question*: are the details of this documented
> anywhere? Chapter 10 refers to ' implicit conversions' but I can't see
> anywhere that the docs explain the details of how it is done, that would
> explain the observed difference in behavior described above.

There are actually no cast defined from numeric to text, so you won't find a
documentation for that.

The first example is working as documented at
https://www.postgresql.org/docs/current/functions-string.html:

anynonarray || text → text
Converts the non-string input to text, then concatenates the two strings. (The
non-string input cannot be of an array type, because that would create
ambiguity with the array || operators. If you want to concatenate an array's
text equivalent, cast it to text explicitly.)

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2022-11-14 11:49:26 Mistake in Syntax definition of ALTER TABLE
Previous Message Kirk Parker 2022-11-11 02:27:21 Implicit type conversion -- where documented?