I have complicated queries like
if schema_arg:
dynamic_schema = f'{schema_arg}.'
else:
dynamic_schema = ''
query_to_compile = f"CREATE TABLE AS {dynamic_schema}{dynamic_table} AS SELECT * FROM ({query_first} UNION ALL {query_second}) GROUP BY f {field_1} {field_2} {field_3}"
Obviously, this isn't usually a good idea to use strings like this (there doesn't seem to be a good dialect-based SQL escaping). I tried the psycopg2.SQL() way but it failed.
Is the only way to use the object oriented way?
Does anyone have a script that can convert any complicated raw SQL into object oriented way for SQLAlchemy?
CREATE TABLE ... ASout of the box. The way SQLA does it is that it compiles the SQLA constructs down to raw SQL, applying escaping/quoting etc. See stackoverflow.com/questions/30575111/…