Re: CAST from numeric(18,3) to numeric doesnt work, posgresql 13.3

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Ján Pecsők <jan(dot)pecsok(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: CAST from numeric(18,3) to numeric doesnt work, posgresql 13.3
Date: 2021-08-05 09:06:26
Message-ID: CAEZATCWcOOGcYwTV0pv2F0o07w+dL7A2JN88fq5U-K29i=Ls=A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, 5 Aug 2021 at 02:35, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Hmm, interesting. The cause of this is that coerce_type_typmod
> supposes that casting to a -1 typmod is a total no-op. Which
> is true so far as the run-time behavior is concerned, but not
> if something inspects the exposed type of the expression.
>
> The attached seems to be enough to fix it, though I wonder if
> we've made the same assumption anywhere else.

+1 for fixing this.

> Although this changes no existing regression test results,
> I'm still a bit hesitant to back-patch it, because I am not
> real sure that nothing out there is depending on the current
> behavior (which has stood for decades). I think it'd be all
> right to put into HEAD, and maybe it's not too late for v14.

This isn't the first time someone has hit this [1]. The failing CTE
query there is quite interesting because if ::varchar[] with no typmod
wasn't a no-op, it could have been used to fix it. In fact, that's
what the error message and hint suggest doing.

So this fix is potentially more widely useful, though I couldn't say
whether anyone is relying on the current behaviour.

Regards,
Dean

[1] https://dba.stackexchange.com/questions/116218/surprising-results-for-data-types-with-type-modifier

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Etsuro Fujita 2021-08-05 11:19:35 Re: BUG #16631: postgres_fdw tries to insert into generated columns
Previous Message PG Bug reporting form 2021-08-05 07:31:56 BUG #17134: pg_restore ERROR: operator does not exist: util.ltree = util.ltree