From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kip Cole <kipcole9@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Casting a collation in an ORDER BY ... COLLATE
Date: Sat, 21 May 2022 19:55:02 -0400
Message-ID: <911566.1653177302@sss.pgh.pa.us> (raw)
In-Reply-To: <DAAAF3FE-890E-44C7-AD59-04C16AC859B7@gmail.com>
References: <DAAAF3FE-890E-44C7-AD59-04C16AC859B7@gmail.com>
Kip Cole <kipcole9@gmail.com> writes:
> cldr_sql=# select * from models order by name collate 'en-x-icu'::regcollation;
> ERROR: syntax error at or near "'en-x-icu'"
> LINE 1: select * from models order by name collate 'en-x-icu'::regco…
You've got the syntax off a bit. The argument of COLLATE is an
identifier, not a string literal (or expression), so you should write
select * from models order by name collate "en-x-icu";
The double quotes are needed because most collation names don't
follow SQL identifier rules.
> Utilmately the objective is to interpolate the collation value into a prepared query so
> this is just the first step to validate that casting a COLLATE name is possible or not.
If you mean that you want to inject a run-time-variable collation
name, you can't, any more than you can inject (say) a run-time-variable
table name. You'd have to construct and execute a dynamic SQL string.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, kipcole9@gmail.com
Subject: Re: Casting a collation in an ORDER BY ... COLLATE
In-Reply-To: <911566.1653177302@sss.pgh.pa.us>
References: <DAAAF3FE-890E-44C7-AD59-04C16AC859B7@gmail.com> <911566.1653177302@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox