samuelcolvin / buildpg

Query building for the postgresql prepared statements and asyncpg.
MIT License
85 stars 12 forks source link

Uppercase column names in Values #20

Open nicwest opened 4 years ago

nicwest commented 4 years ago
>>> render(":values__names", values=Values(FOO=1, BAR=2))
('FOO, BAR', [])
>>> render(":values__names", values=Values(**{'"FOO"':1, '"BAR"':2}))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nic/.local/share/virtualenvs/nic-UOxQ1ZmO/lib/python3.7/site-packages/buildpg/components.py", line 96, in __init__
    check_word_many(self.names)
  File "/home/nic/.local/share/virtualenvs/nic-UOxQ1ZmO/lib/python3.7/site-packages/buildpg/components.py", line 30, in check_word_many
    raise UnsafeError(f'raw arguments contain unsafe (non word) characters: {unsafe}')
buildpg.components.UnsafeError: raw arguments contain unsafe (non word) characters: ['"FOO"', '"BAR"']

Postgres doesn't distinguish between a column named foo and a column named FOO unless you put the column name in double quotes "FOO".

Is there a way to allow unsafe or mark a name safe?