str representation of query not compatible with Table.raw when using uuid/date columns
Discussed in https://github.com/piccolo-orm/piccolo/discussions/403
Originally posted by theelderbeever January 25, 2022 Version info: piccolo = "0.64.0"
I am attempting to use some of the query building tools to generate custom complex queries that aren't directly possible through the ORM at the moment. During this I ran into a case where Attempting to run the str(MyTable.insert(MyTable())) doesn't seem to work with uuid or date columns as they aren't wrapped in ''.
I believe the following minimal example should work
from datetime import datetime
from piccolo.columns import UUID, Timestamptz
from piccolo.table import Table
class Table(Table):
uuid = UUID(primary_key=True)
created_at = Timestamptz(default=datetime.now, index=True)
updated_at = Timestamptz(default=datetime.now, index=True)
# Instantiate an instance
table = Table()
Table.raw(str(Table.insert(table))).run_sync()
It is contrived but the query fails with a SQL error midway through the UUID string that gets output. The uuid value should be wrapped in '' I believe.
Example Error
PostgresSyntaxError: syntax error at or near "fa"
This seems to come down to how the Table.querystring is formed. The values don't get wrapped and the datetime doesn't replace the ' ' with a T. Relevant Code
>>> print(table.querystring)
(3a47b208-4834-4d0d-9213-db3511a52886,2022-01-25 16:58:44.238463+00:00,2022-01-25 16:58:44.238470+00:00)
Ultimate goal here is that I am writing some custom on conflict statements and was taking inspiration from the Insert.postgres_querystrings method to construct them when I ran into this.