Re: Casting a collation in an ORDER BY ... COLLATE

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Kip Cole <kipcole9(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Casting a collation in an ORDER BY ... COLLATE
Date: 2022-05-21 23:53:15
Message-ID: CAKFQuwbauC7PnJu7qLVL2NkpoYUhZz2j0cO9rn+neoC+Uko4Jg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, May 21, 2022 at 4:38 PM Kip Cole <kipcole9(at)gmail(dot)com> wrote:

> I’m trying to cast a string value to a collation name without success. My
> suspicion is this isn’t possible
> based upon the error message.

You cannot cast between a token that interpreted as a literal and one that
is interpreted as a name. For example: SELECT * FROM 'table_name'::???;
you need to supply an identifier in the FROM clause, not a literal.

Identifiers cannot be parameterized, so if you want to interpolate you need
to do so while building a dynamic query string. See the "format()"
function and "EXECUTE" command for ways to do this within the server. Or
use whatever client-side facilities you have at your disposal.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-05-21 23:55:02 Re: Casting a collation in an ORDER BY ... COLLATE
Previous Message Kip Cole 2022-05-21 23:38:45 Casting a collation in an ORDER BY ... COLLATE