Re: CAST from numeric(18,3) to numeric doesnt work, posgresql 13.3 - Mailing list pgsql-bugs

From Dean Rasheed
Subject Re: CAST from numeric(18,3) to numeric doesnt work, posgresql 13.3
Date
Msg-id CAEZATCWcOOGcYwTV0pv2F0o07w+dL7A2JN88fq5U-K29i=Ls=A@mail.gmail.com
Whole thread Raw
In response to Re: CAST from numeric(18,3) to numeric doesnt work, posgresql 13.3  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: CAST from numeric(18,3) to numeric doesnt work, posgresql 13.3  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Thu, 5 Aug 2021 at 02:35, Tom Lane <tgl@sss.pgh.pa.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



pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #17134: pg_restore ERROR: operator does not exist: util.ltree = util.ltree
Next
From: Etsuro Fujita
Date:
Subject: Re: BUG #16631: postgres_fdw tries to insert into generated columns