coerce_type discard unnecessary CollateExprs
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t248668psql -h localhost -U postgresBuilt from patchset v1 (message #1), September 20, 2026 at 07:03 AM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t248668_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t248668_1 && git checkout t248668_1Patchset v1 (message #1) is on t248668_1
Hi.
In coerce_to_target_type, we have comments like
/*
* Note that if there are multiple stacked CollateExprs, we just
discard all but the topmost.
*/
origexpr = expr;
while (expr && IsA(expr, CollateExpr))
expr = (Node *) ((CollateExpr *) expr)->arg;
Only the topmost CollateExpr will be used, all others will be dropped.
We can apply this to coerce_type also.
See the attached minor patch.
jian he <jian.universality@gmail.com> writes:
Only the topmost CollateExpr will be used, all others will be dropped.
We can apply this to coerce_type also.
See the attached minor patch.
It's not apparent to me that this does anything (will there ever
be a CollateExpr at this stage?), or that it's correct if it does.
Please provide an example. Not to mention a comment.
regards, tom lane
On Mon, Jun 29, 2026 at 9:38 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
jian he <jian.universality@gmail.com> writes:
Only the topmost CollateExpr will be used, all others will be dropped.
We can apply this to coerce_type also.
See the attached minor patch.It's not apparent to me that this does anything (will there ever
be a CollateExpr at this stage?), or that it's correct if it does.
Please provide an example. Not to mention a comment.
will there ever be a CollateExpr at this stage?)
Yes. We use coerce_to_target_type->coerce_type, but some places we
just use coerce_type directly.
For example ParseFuncOrColumn->make_fn_arguments->coerce_type
select to_char(1, 'x' collate "C" collate "POSIX");
Without the patch: After make_fn_arguments->coerce_type the second fargs is:
{COLLATEEXPR
:arg
{COLLATEEXPR
:arg
{CONST
:consttype 25
:consttypmod -1
:constcollid 100
:constlen -1
:constbyval false
:constisnull false
:location 18
:constvalue 5 [ 20 0 0 0 120 ]
}
:collOid 950
:location 22
}
:collOid 951
:location 34
}
With the patch:
{COLLATEEXPR
:arg
{CONST
:consttype 25
:consttypmod -1
:constcollid 100
:constlen -1
:constbyval false
:constisnull false
:location 18
:constvalue 5 [ 20 0 0 0 120 ]
}
:collOid 951
:location 34
}