Closed
Description
when a compoundselect is invoked directly, the columns of all the subsequent SELECTs need to have col_expression applied:
from sqlalchemy import cast
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import TypeDecorator
class StringDate(TypeDecorator):
impl = DateTime
def column_expression(self, col):
return cast(col, String)
meta = MetaData()
t = Table(
"t",
meta,
Column("Id", Integer, primary_key=True),
Column("x", StringDate),
)
t_history = Table(
"t_history",
meta,
Column("Id", Integer),
Column("x", StringDate),
)
print(t.select().union_all(t_history.select()))
returns:
SELECT t."Id", CAST(t.x AS VARCHAR) AS x
FROM t UNION ALL SELECT t_history."Id", t_history.x
FROM t_history
workaround is of course to call select() from that:
print(t.select().union_all(t_history.select()))
which is why this is not an ORM issue
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqla-tester commentedon Jul 29, 2019
Mike Bayer has proposed a fix for this issue in the master branch:
Invoke column_expression() for subsequent SELECTs in CompoundSelect https://gerrit.sqlalchemy.org/1383
sqla-tester commentedon Jul 29, 2019
Mike Bayer has proposed a fix for this issue in the rel_1_3 branch:
Invoke column_expression() for subsequent SELECTs in CompoundSelect https://gerrit.sqlalchemy.org/1384
Invoke column_expression() for subsequent SELECTs in CompoundSelect