python - SQLAlchemy insert select query from case statement to FROM clause -



python - SQLAlchemy insert select query from case statement to FROM clause -

i have case statement saved in variable like:

article_video_exists = exists( select([1], correlate=false, from_obj=article_video_t).where( article_video_t.c.article_id == article_t.c.id)) has_videos_case = case([(article_video_exists, 1), ], else_=0).label( 'has_videos')

and utilize case

select([has_videos_case], from_obj=article_t)

after executing, saw in query statement

from article_t, (select 1 article_video_t article_video_t.article_id=article_t.id)

and error should utilize alias. tried utilize alias select in case, it's not fixed problem. tried pass correlate=false select clauses, it's not help, if pass case in final select clause without using variable, it's work , not generate invalid clause.

but after have many duplicating code, how utilize variable case in situation? thanks.

fixed using select(...).correlate_except(article_video_t).

python sql sqlalchemy

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -