Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nsYw9-0007DS-Se for pgsql-general@arkaria.postgresql.org; Sat, 21 May 2022 23:55:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nsYw8-0003l2-Nr for pgsql-general@arkaria.postgresql.org; Sat, 21 May 2022 23:55:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nsYw8-0003kr-DR for pgsql-general@lists.postgresql.org; Sat, 21 May 2022 23:55:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nsYw5-0004wZ-9J for pgsql-general@lists.postgresql.org; Sat, 21 May 2022 23:55:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 24LNt2iv911567; Sat, 21 May 2022 19:55:02 -0400 From: Tom Lane To: Kip Cole cc: pgsql-general@lists.postgresql.org Subject: Re: Casting a collation in an ORDER BY ... COLLATE In-reply-to: References: Comments: In-reply-to Kip Cole message dated "Sun, 22 May 2022 07:38:45 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <911565.1653177302.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 21 May 2022 19:55:02 -0400 Message-ID: <911566.1653177302@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Kip Cole writes: > cldr_sql=3D# select * from models order by name collate 'en-x-icu'::regc= ollation; > ERROR: syntax error at or near "'en-x-icu'" > LINE 1: select * from models order by name collate 'en-x-icu'::regco=E2=80= =A6 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 pr= epared 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