Skip to content

How would i go about converting the following raw query to the new on_conflict op? #822

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

You must be logged in to vote

Give this a go:

from piccolo.querystring import QueryString

await Player.insert(
    Player(...)  # Whichever rows you want to upsert
).on_conflict(
    action='DO UPDATE',
    target=(Player.id, Player.bot),  # assuming you have a composite unique constraint on these columns
    values=[(Player.dj_roles, QueryString('array_cat(player.dj_roles, EXCLUDED.dj_roles)')]
)

We're passing in the SQL for the value to update using QueryString. This isn't really documented anywhere, but QueryString is the building block of queries internally.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Drapersniper
Comment options

Answer selected by Drapersniper
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