Skip to content

PostgreSQL: renaming an attribute of a dj.U restriction quotes it with backticks #1638

Open

Description

@dimitri-yatsenko

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.

Activity

  1. added this to the v2.4 milestone on Oct 18, 2026
  2. added
    bugIndicates an unexpected problem or unintended behavior
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions