MagicStack / MagicStack/asyncpg

Support composite types with fields that are of type `citext`

Offen
#1,075 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
8.1k
Forks
468
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

* **asyncpg version**: 0.28
* **PostgreSQL version**: 15
* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: Local version
* **Python version**: 3.11
* **Platform**: Linux
* **Do you use pgbouncer?**: No
* **Did you install asyncpg with pip?**: Yes
* **If you built asyncpg locally, which version of Cython did you use?**: -
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**: not tested

I am using citext for fields that really need to be citext (as in, I care about the case only for displaying but other than that the case should not matter). Now I have a query that goes like

```sql
SELECT * FROM project WHERE (owner::citext, name::citext)::record = ANY($1);
```

Throughout asyncpg it is mentioned to get this to work (normally) you add a composite type. So we add a composite type and cast the array to the composite type.
```sql
CREATE TYPE project_fqn AS (
owner citext,
name citext
);

SELECT * FROM project WHERE (owner::citext, name::citext) = ANY($1::project_fqn[]);
```

Sadly this fails due to an `: cannot decode type "public"."project_fqn": text encoding of composite types is not supported.` error. It can be "fixed" by changing all `citext` types for a `text` type but then we lose the case insensitive search.

Is this something that can be fixed or are there any workarounds? I tried doing a `set_builtin_type_codec("citext", codec_name=25)` but that seems to have no impact.

Some references:
- https://github.com/MagicStack/asyncpg/issues/476
- https://github.com/MagicStack/asyncpg/issues/82

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere die gemeldete SQL-Abfrage mit asyncpg 0.28 unter PostgreSQL 15 und einem zusammengesetzten Typ, dessen Felder citext sind. Beginne damit, die Dekodierung zusammengesetzter Typen und den Einstiegspunkt set_builtin_type_codec("citext") nachzuverfolgen; abgeschlossen ist die Aufgabe, wenn project_fqn[]-Werte ohne UnsupportedClientFeatureError dekodiert werden und dabei das citext-Verhalten erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
postgresql, python
Bereich
databases
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.