Skip to content

How to handle a row UPDATE with multiple updateable fields, but only a subset of them need updating #1149

Answered by rhyselsmore
app-o-matix asked this question in Q&A
Discussion options

You must be logged in to vote

This is how I do it - based off an excellent blog post by @brandur.

-- name: UpdateWorkspace :exec
UPDATE workspaces
SET
    state = CASE WHEN @state_do_update::boolean
        THEN @state::workspace_state ELSE state END
WHERE
    id = @id::uuid;

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by kyleconroy
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
3 participants