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

str representation of query not compatible with Table.raw when using uuid/date columns #404

Open
theelderbeever opened this issue Jan 25, 2022 Discussed in #403 · 0 comments

Comments

@theelderbeever
Copy link
Contributor

Discussed in #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.

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

No branches or pull requests

1 participant