- changed component to orm
- changed milestone to 0.7.0
- changed title to Cast(NULL AS CLOB) fails on oracle, doesnt work w current polymorphic_union
Cast(NULL AS CLOB) fails on oracle, doesnt work w current polymorphic_union
I found an issue w/casting NULLs as CLOBs with the oracle compiler. Oracle does not support this operation, you get "ORA-00932: inconsistent datatypes: expected - got CLOB"
I made the following fix to get around the issue. I was seeing this behavior in the polymorphic join generator.
# FIX FOR CAST(NULL AS CLOB)
def visit_cast(self, cast, **kwargs):
if cast.clause.type == sqltypes.NULLTYPE \
and isinstance(cast.type,OracleText) :
return "NULL"
else :
return "CAST(%s AS %s)" % \
(self.process(cast.clause),self.process(cast.typeclause))
Comments (7)
-
repo owner -
repo owner here is the comment in the extremely old changeset that introduced the "cast":
then, polymorphic_union() function now CASTs null()s to the type corresponding to the columns in the UNION, since postgres doesnt like mixing NULL with integer types
so need to poke around and see what that's about. was it an old version of PG, or do we just not have tests for integer polymorphic_on.
-
repo owner shrugs, these all work with psycopg2 and pg8000 too:
from sqlalchemy import * e = create_engine('postgresql://scott:tiger@localhost/test', echo=True) print e.execute("select * from (select null union select cast(5 as decimal)) as foo").fetchall() print e.execute("select * from (select null union select cast(5 as int)) as foo").fetchall() print e.execute("select * from (select null union select 5) as foo").fetchall()
-
repo owner i.e. the "decimal" cast gets picked up and we get Decimal("5") back, otherwise int, etc.
-
repo owner even as far back as 8.1 they document the behavior this way: http://www.postgresql.org/docs/8.1/static/typeconv-union-case.html.
I would propose use type_coerce(), make sure a test for poly union exists by itself using varchar, char, int, and text, run the test on s/p/m/f/o backends, we're done.
-
repo owner - changed status to resolved
its too late for me to make a bigger change here so I've added a flag that turns of the CAST in 9826ba73a6a614a92be7104474428dde40c2d773.
-
repo owner - removed milestone
Removing milestone: 0.7.0 (automated comment)
- Log in to comment
running tests against sqlite, pg, mysql, I see that this works:
and even this works:
so need to figure out the rationale for the cast() in the first place. I'd like to just change polymorphic_union here instead.