Skip to content

PostgreSQL stores a backslash before each double quote in an attribute comment #1729

Open

Description

@dimitri-yatsenko

Problem

compile_attribute in declare.py writes a double quote in an attribute comment as \". MySQL reads \" inside its string literal as a plain ". PostgreSQL does not treat a backslash as an escape in a standard string literal, so it stores the backslash too.

Reproduction

@schema
class T(dj.Manual):
    definition = """
    t_id : int32
    ---
    note : varchar(8)  # say "hi"
    """

T.heading["note"].comment
  • MySQL: say "hi"
  • PostgreSQL: say \"hi\"

Effects on PostgreSQL

  • describe() shows the backslashes, and each declaration from that output adds another pair.
  • With alter() changes and renames attributes on PostgreSQL #1639, alter() compares comments. For this table, alter() with an unchanged definition emits a COMMENT ON COLUMN every time and never reports that there is nothing to alter.

Expected behavior

The stored comment is say "hi" on both backends. The escaping could move into the adapters, or the comment could be written with the adapter's string quoting, so that each backend gets the escape it needs.

Reported in review of #1639. The escaping predates that PR.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions