diff --git a/singer_sdk/sinks/sql.py b/singer_sdk/sinks/sql.py index 3a37570d6..991ba431a 100644 --- a/singer_sdk/sinks/sql.py +++ b/singer_sdk/sinks/sql.py @@ -10,6 +10,7 @@ import sqlalchemy as sa from pendulum import now +from sqlalchemy.sql import quoted_name from sqlalchemy.sql.expression import bindparam from singer_sdk.connectors import SQLConnector @@ -279,10 +280,14 @@ def generate_insert_statement( An insert statement. """ property_names = list(self.conform_schema(schema)["properties"].keys()) + column_identifiers = [ + self.connector.quote(quoted_name(name, quote=True)) + for name in property_names + ] statement = dedent( f"""\ INSERT INTO {full_table_name} - ({", ".join(property_names)}) + ({", ".join(column_identifiers)}) VALUES ({", ".join([f":{name}" for name in property_names])}) """, # noqa: S608 ) diff --git a/tests/samples/test_target_sqlite.py b/tests/samples/test_target_sqlite.py index 0d34c60a1..edf88ee92 100644 --- a/tests/samples/test_target_sqlite.py +++ b/tests/samples/test_target_sqlite.py @@ -484,14 +484,15 @@ def test_record_with_missing_properties( "properties": { "id": {"type": "integer"}, "name": {"type": "string"}, + "table": {"type": "string"}, }, }, [], dedent( """\ INSERT INTO test_stream - (id, name) - VALUES (:id, :name)""", + (id, name, "table") + VALUES (:id, :name, :table)""", ), ), ],