11

I tried to reflect an existing oracle database into sqlalchemy metadata:

from sqlalchemy import create_engine
from sqlalchemy import MetaData
from sqlalchemy import Table

db_uri = 'oracle://USER:PASS@MYDBTNSNAME'
engine = create_engine(db_uri)

# create a MetaData instance
metadata = MetaData()

# reflect db schema to MetaData
metadata.reflect(bind=engine)

This returns the following:

SAWarning: Did not recognize type 'BINARY_DOUBLE' of column 'column_1'(coltype, colname))

I have tried to import native types and also the types from dialect oracle using

from sqlalchemy.types import *
from sqlalchemy.dialects.oracle import *

but it seems it does not recognize BINARY_DOUBLE type

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-b69d481f6a4e> in <module>()
      1 from sqlalchemy.types import *
----> 2 from sqlalchemy.dialects.oracle import *

AttributeError: module 'sqlalchemy.dialects.oracle' has no attribute 'BINARY_DOUBLE'

I am using SQLAlchemy, version '1.2.1'

3
  • 1
    Probably you need this. Which mentioned the fix as from sqlalchemy.dialects.oracle.base import ischema_names and ischema_names['BINARY_DOUBLE'] = OracleBinaryDouble this Commented Mar 26, 2018 at 9:05
  • @TarunLalwani I tried it. If I didn't miss anything, it only maps the column type to NullType() after applying metadata.reflect() function. I need to map it to something like cx-oracle.readthedocs.io/en/latest/… Commented Mar 26, 2018 at 13:48
  • Unfortunately don't have oracle to test and debug what it does Commented Mar 26, 2018 at 13:52

3 Answers 3

1

Have you tried overriding the default mapping relfection in your db? Like so

from sqlalchemy.dialects.oracle.base import BINARY_DOUBLE

group_table = sa.Table('groups', metadata,
    sa.Column('your_column', BINARY_DOUBLE(asdecimal=True)),
    autoload=True,
    include_columns=[
    'your_column',
    '...'
    ],
)

Or just importing that BINARY_DOBULE from sqlalchemy.dialects.oracle.base

I'd ask that in a comment, but I can't do so as I just joined.

Sign up to request clarification or add additional context in comments.

1 Comment

Just importing BINARY_DOUBLE from sqlalchemy.dialects.oracle.base does assign NullType() when using metadata.reflect(bind=engine). Therefore, it does not solve the problem
1

As described in sqlalchemy changelog, this functionality has been included in version 1.2.8:

[oracle] [bug] Added reflection capabilities for the oracle.BINARY_FLOAT, oracle.BINARY_DOUBLE datatypes

I have checked it using 1.2.18 version and now reflection works.

Comments

0

You're trying to use a column type that is not well supported by sqlalchemy / DB driver. So avoid that type.

Create a view as (roughly) SELECT * FROM base_table, with the minor tweak of casting binary double columns to a more convenient numeric type. Then reflect the view.

1 Comment

I cannot change the database schema. My question is how to make SQLAlchemy handle BINARY_DOUBLE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.