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

SNOW-1745924: Underscore as column name not properly escaped #535

Open
ifoukarakis opened this issue Oct 17, 2024 · 1 comment
Open

SNOW-1745924: Underscore as column name not properly escaped #535

ifoukarakis opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working needs triage

Comments

@ifoukarakis
Copy link

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

Python 3.10.10

  1. What operating system and processor architecture are you using?

macOS-14.5-arm64-arm-64bit

  1. What are the component versions in the environment (pip freeze)?

snowflake-connector-python==3.12.2
snowflake-sqlalchemy==1.5.1
SQLAlchemy==1.4.51

  1. What did you do?

Created a table where a column name is _. Then tried to insert into the column.

import os

from sqlalchemy import Table, MetaData, Column, Integer, VARCHAR, create_engine, insert
from snowflake.sqlalchemy import URL

metadata = MetaData(schema="test_schema")
test_table = Table(
    'test_table',
    metadata,
    Column('col_a', Integer),
    Column('col_b', VARCHAR(100)),
    Column('_', VARCHAR(100)),
)

engine = create_engine(...)


with engine.connect() as conn:
    conn.execute(insert(test_table).values(col_a=1, col_b='test', _='test'))

Instead I got an exception:

sqlalchemy.exc.ProgrammingError: (snowflake.connector.errors.ProgrammingError) 001003 (42000): SQL compilation error:
syntax error line 1 at position 54 unexpected '_'.
[SQL: INSERT INTO test_schema.test_table (col_a, col_b, _) VALUES (%(col_a)s, %(col_b)s, %(_)s)]
[parameters: {'col_a': 1, 'col_b': 'test', '_': 'test'}]
(Background on this error at: https://sqlalche.me/e/14/f405)
  1. What did you expect to see?

A row inserted in the table.

@ifoukarakis ifoukarakis added bug Something isn't working needs triage labels Oct 17, 2024
@github-actions github-actions bot changed the title Underscore as column name not properly escaped SNOW-1745924: Underscore as column name not properly escaped Oct 17, 2024
@ifoukarakis
Copy link
Author

ifoukarakis commented Oct 17, 2024

A workaround is to manually set engine.dialect.preparer.reserved_words.add('_') to force escaping of _.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant