Skip to content

generate_sql_schema column name wrapping #73

@rokf

Description

@rokf

Hello,

I've opened a few issues in other model-specific repositories on the same topic - sometimes properties in YAML files that are used as a base for SQL schema file generation are also valid keywords in PostgreSQL (DuckDB and other PostgreSQL-compatible databases as well).

This causes the resulting schema.sql files to be unusable - they can't be applied without modification.

I believe that generate_sql_schema is used to generate all those schema.sql files in model repositories?

I propose a simple fix - let's just quote all the column names in the CREATE TABLE statements. I wouldn't personally add a keyword blacklist for exceptions since that isn't future proof and would eventually break the generator if a keyword would be added or removed to PostgreSQL. Different PostgreSQL compatible (SQL syntax) databases can also potentially have some keyword differences 🤷

Changing the few sql_schema_statements.append(f"{key} {field_type}") (and similar) lines would probably be enough to fix this issue. Something like sql_schema_statements.append(f"\"{key}\" {field_type}").

Thank you!

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