PostgreSQL: renaming an attribute of a dj.U restriction quotes it with backticks
Les mainteneurs répondent en général sous 4 jours
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 75/100
Piste de recherche
Start by reading Heading.set_primary_key and the projection code that quotes renamed attributes, then reproduce the issue with the supplied dj.U example on PostgreSQL 15. Compare the generated SQL and behavior with MySQL to trace where backend quoting is lost. The change is complete when the PostgreSQL query uses backend-appropriate quoting and returns [10, 20] from to_arrays("c"), with regression coverage if the project’s test layout provides a suitable location.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
On PostgreSQL, renaming an attribute in a projection of a dj.U restriction produces invalid SQL. (dj.U("b") & T).proj(c="b") compiles to SELECT DISTINCT `b` as "c" ...: the renamed attribute is quoted with MySQL backticks, which PostgreSQL rejects. MySQL returns the right rows.
The cause appears to be Heading.set_primary_key, which builds the new heading without table_info. The projection then quotes the attribute without the connection's adapter, and falls back to backticks.
Reproduction
DataJoint master, PostgreSQL 15:
import datajoint as dj
schema = dj.Schema("scratch_u_proj")
@schema
class T(dj.Manual):
definition = """
a : int32
---
b : int32
"""
T.insert([(1, 10), (2, 10), (3, 20)])
(dj.U("b") & T).proj(c="b").to_arrays("c")
# QuerySyntaxError: syntax error at or near "as"
# LINE 1: SELECT DISTINCT `b` as "c" FROM "scratch_u_proj"."t"
On MySQL the same query returns [10, 20].
Expected behavior
The projection quotes every attribute for the connection's backend, and returns [10, 20] on PostgreSQL too.
- Langage dominant
- Python
- Étoiles
- 197
- Forks
- 101
- Merge moyen
- 3 j 8 h
- PR mergées (30 j)
- 28
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de datajoint/datajoint-python
-
len() of an expression with an empty primary key generates invalid SQLPeut-être pris @dimitri-yatsenko l’a pris il y a 4 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
datajoint/datajoint-python#1581 ·
Les mainteneurs répondent en général sous 4 jours
-
dj.Diagram theme: make the font configurablePeut-être pris @dimitri-yatsenko l’a pris il y a 4 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
datajoint/datajoint-python#1539 · 3 commentaires ·
Les mainteneurs répondent en général sous 4 jours
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
datajoint/datajoint-python#1644 · 1 commentaire ·
Les mainteneurs répondent en général sous 4 jours
-
bug
Difficulté 4/5 1-2 jours Accessibilité débutants 68/100
datajoint/datajoint-python#1641 ·
Les mainteneurs répondent en général sous 4 jours
-
A join on namesake secondary attributes raises the stale-`~lineage` error on a freshly declared schemaPeut-être pris @dimitri-yatsenko l’a pris il y a 4 jours. Ouvertebug
Difficulté 3/5 1-2 jours Accessibilité débutants 82/100
datajoint/datajoint-python#1640 · 1 commentaire ·
Les mainteneurs répondent en général sous 4 jours
Toutes les issues de datajoint/datajoint-python
Issues similaires
-
bug good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
yunaremaia/proto-drift#22 ·
-
bug good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
yunaremaia/memwatch#96 ·
-
bug good first issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 91/100
yunaremaia/ci-gate-watch#34 ·
-
bug good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
yunaremaia/agent-capability-attestation#64 ·
Les mainteneurs répondent en général sous 1 jour
-
bug good first issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 86/100
yunaremaia/agent-call-graph#43 ·
Les mainteneurs répondent en général sous 1 jour