Skip to content

Instantly share code, notes, and snippets.

@tsauerwein
Created October 15, 2016 08:51
Show Gist options
  • Save tsauerwein/09590bb1f4175dae44084427d6713999 to your computer and use it in GitHub Desktop.
Save tsauerwein/09590bb1f4175dae44084427d6713999 to your computer and use it in GitHub Desktop.
SQLAlchemy: Using raw SQL in ORM statements
# ...
participants_and_editor = text(
'ARRAY(SELECT DISTINCT UNNEST(array_cat('
' ARRAY[guidebook.feed_document_changes.user_id], :participants)) '
'ORDER BY 1)')
DBSession.execute(
DocumentChange.__table__.update().
where(DocumentChange.document_id == outing_id).
where(DocumentChange.change_id != existing_change.change_id).
values(user_ids=participants_and_editor),
{'participants': participant_ids}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment