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

🐛 Bug: columns that match SQL reserved words cause failure during insert #7

Closed
flash1293 opened this issue Feb 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@flash1293
Copy link
Contributor

flash1293 commented Feb 5, 2024

When the final table is created in SQL caches, field names matching SQL keywords cause the query to break.

For example when reading from the pokeapi connector, the following query is issued:

CREATE TABLE main.pokemon (
  id VARCHAR,
  name VARCHAR,
  base_experience VARCHAR,
  height VARCHAR,
  is_default VARCHAR,
  order VARCHAR,
  weight VARCHAR,
  abilities VARCHAR,
  forms VARCHAR,
  game_indices VARCHAR,
  held_items VARCHAR,
  location_area_encounters VARCHAR,
  moves VARCHAR,
  sprites VARCHAR,
  species VARCHAR,
  stats VARCHAR,
  types VARCHAR,
  past_types VARCHAR
)

As order is also a SQL keyword, the query fails.

This is a problem throughout the SQLCacheBase class which uses string concatenation to interface with the SQL database.

As a stopgap solution the individual places in the code can be patched by escaping field names one by one to avoid having to refactor the whole class:

However, mid term the refactor to sqlachemy should be performed, also to avoid security issues via SQL injection.

@aaronsteers aaronsteers transferred this issue from airbytehq/airbyte Feb 6, 2024
@aaronsteers aaronsteers changed the title airbyte-lib: Escape field names in SQL cache loading Escape field names in SQL cache loading Feb 6, 2024
@aaronsteers aaronsteers changed the title Escape field names in SQL cache loading Bug: columns that match SQL reserved words cause failure during insert Feb 6, 2024
@aaronsteers aaronsteers changed the title Bug: columns that match SQL reserved words cause failure during insert 🐛 Bug: columns that match SQL reserved words cause failure during insert Feb 6, 2024
@aaronsteers aaronsteers added the bug Something isn't working label Feb 6, 2024
@aaronsteers
Copy link
Contributor

aaronsteers pushed a commit that referenced this issue Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants