Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reflect an oracle database with BINARY_DOUBLE type columns

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'

like image 503
aturegano Avatar asked Mar 23 '18 13:03

aturegano


2 Answers

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.

like image 171
aturegano Avatar answered Sep 22 '22 09:09

aturegano


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.

like image 35
Olaf Górski Avatar answered Sep 23 '22 09:09

Olaf Górski