Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(targets): Quote column names in INSERT statement #2198

Closed
wants to merge 4 commits into from

Conversation

mattwill09
Copy link
Contributor

@mattwill09 mattwill09 commented Jan 30, 2024

This is an update to fix how the insert into statements are being generated. If you have a source column that uses a reserved word then invalid SQL was being generated.

Previous:

INSERT INTO analytics.foo
(id, in)
VALUES (:id, :in)

Updated:

INSERT INTO analytics.foo
("id", "in")
VALUES (:id, :in)

📚 Documentation preview 📚: https://meltano-sdk--2198.org.readthedocs.build/en/2198/

@@ -282,7 +282,7 @@ def generate_insert_statement(
statement = dedent(
f"""\
INSERT INTO {full_table_name}
({", ".join(property_names)})
({", ".join([f'"{name}"' for name in property_names])})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not typically a python developer, but that change looks to be easy enough. I'll make sure to get those tests fixed up too.

Copy link

codspeed-hq bot commented Jan 30, 2024

CodSpeed Performance Report

Merging #2198 will not alter performance

Comparing mattwill09:main (342247a) with main (af3b678)

Summary

✅ 6 untouched benchmarks

Copy link

codecov bot commented Jan 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (af3b678) 88.43% compared to head (342247a) 88.44%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2198   +/-   ##
=======================================
  Coverage   88.43%   88.44%           
=======================================
  Files          54       54           
  Lines        4714     4715    +1     
  Branches      961      961           
=======================================
+ Hits         4169     4170    +1     
  Misses        384      384           
  Partials      161      161           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@edgarrmondragon edgarrmondragon changed the title fix generate_insert_statement fix(targets): Quote column names in INSERT statement Jan 30, 2024
Copy link
Collaborator

@edgarrmondragon edgarrmondragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mattwill09!

You may want to update the test in

dedent(
"""\
INSERT INTO test_stream
(id, name)
VALUES (:id, :name)""",
),
.

* Update sql.py

* Update test_target_sqlite.py
singer_sdk/sinks/sql.py Outdated Show resolved Hide resolved
@@ -282,7 +283,7 @@ def generate_insert_statement(
statement = dedent(
f"""\
INSERT INTO {full_table_name}
({", ".join(property_names)})
({", ".join(quoted_name(name, True) for name in property_names)})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
({", ".join(quoted_name(name, True) for name in property_names)})
({", ".join(quoted_name(name, True) for name in property_names)}) # noqa: FBT003

@edgarrmondragon
Copy link
Collaborator

Superseded by #2200. Thanks @mattwill09!

@mattwill09
Copy link
Contributor Author

Thanks for finding a proper solution for this. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants