Skip to content

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

Answered by dantownsend
theelderbeever asked this question in Q&A
Discussion options

You must be logged in to vote

@theelderbeever A solution which might work for you is something like:

from piccolo.querystring import QueryString

# Assuming `Manager` is your table class, and `some_unique_column` is a unique column name:
query = QueryString(
    "{} ON CONFLICT (some_unique_column) DO NOTHING",
    Manager.insert(Manager(name='Guido')).querystrings[0]
)
await Manager._meta.db.run_querystring(query)

Internally Piccolo uses this QueryString class to compose queries, and then compiles them into a parameterised SQL statement, and values.

We don't really expose the ability to run these QueryString objects in an elegant way, but they are the best solution for composing your own queries. We could probably mo…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@theelderbeever
Comment options

@dantownsend
Comment options

Answer selected by theelderbeever
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants