From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Kip Cole <kipcole9(at)gmail(dot)com> |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Casting a collation in an ORDER BY ... COLLATE |
Date: | 2022-05-21 23:55:02 |
Message-ID: | 911566.1653177302@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Kip Cole <kipcole9(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Rama Krishnan | 2022-05-23 06:03:14 | |
Previous Message | David G. Johnston | 2022-05-21 23:53:15 | Re: Casting a collation in an ORDER BY ... COLLATE |