Skip to content

Proper SQL identifier parameterization in PostgreSQL loader#53

Open
fordN wants to merge 1 commit intomainfrom
ford/sql-identifier-handling
Open

Proper SQL identifier parameterization in PostgreSQL loader#53
fordN wants to merge 1 commit intomainfrom
ford/sql-identifier-handling

Conversation

@fordN
Copy link
Copy Markdown
Contributor

@fordN fordN commented Apr 14, 2026

This PR addresses the concern raised by Aikido in #48 (SQL identifier concatenation) properly, and also covers the column quoting gap tracked in #52. Rather than a one-off regex validation, this uses psycopg2's built-in sql module which handles reserved keywords, schema-qualified names, and special characters correctly.

Changes

  • Replace all f-string SQL interpolation of table/column names with psycopg2.sql.Identifier
  • Switch COPY path from copy_from to copy_expert so both table and column identifiers can be
    properly quoted
  • Covers all 6 SQL construction sites: TRUNCATE, COPY, INSERT, CREATE TABLE, CREATE INDEX, DELETE

Closes #52

Replace f-string interpolation of table and column names with
psycopg2.sql.Identifier across all SQL construction sites in the
PostgreSQL loader. This is the driver's own escaping logic and
handles reserved keywords and special characters correctly.

Also switches COPY from copy_from to copy_expert, which allows
quoting both table and column identifiers via sql.SQL.
@fordN fordN self-assigned this Apr 14, 2026
@fordN fordN changed the title Use psycopg2.sql for safe SQL identifier parameterization Improve SQL identifier parameterization in PostgreSQL loader Apr 14, 2026
@fordN fordN changed the title Improve SQL identifier parameterization in PostgreSQL loader Proper SQL identifier parameterization in PostgreSQL loader Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quote column identifiers in PostgreSQL COPY path

1 participant