Skip to content

Add quotes around column names/table names #21

Closed
@tamino-martinius

Description

@tamino-martinius

Postgres supports camel cased column and table names - but only when you quote your table/column names. Same for column names which use reserved words - they also need to be quoted.

sql`SELECT * from ${sql('tableName')} where ${sql({firstName: 'John'})}`

This generates the sql query SELECT * from tableName where firstName = $1
Which will fail if you used camelCased names while creating the table
SELECT * from "tableName" where "firstName" = $1 would be the expected query.

Not that important, but also related and unexpected is that dollar quoted names become quoted

sql`SELECT * from ${sql('$$table_name$$')} where ${sql({firstName: 'John'})}`

This generates the sql query SELECT * from "$$table_name$$" where firstName = $1
Which will fail as $$ are already quotes
SELECT * from $$table_name$$ where "firstName" = $1 would be the expected query.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions