Skip to content

How to do case statement in order #819

Answered by Pentusha
fcennecf asked this question in Q&A
Discussion options

You must be logged in to vote

I ran into a similar problem once and solved it with additional cast from string to integer:

from sqlalchemy import case, cast
from sqlalchemy.dialects.postgresql import INTEGER

cast(
    case([
        (Record.name == name, '0'),
    ], else_='1'),
    type_=INTEGER,
)

Replies: 1 comment 1 reply

Comment options

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

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