Closed GoogleCodeExporter closed 9 years ago
Original comment by apiti...@ca.ibm.com
on 7 Mar 2008 at 6:21
[deleted comment]
Hi Florian,
While the generated SQL is obviously failing to create the table, I believe the
expectations are probably not quite correct:
If this is what's issued:
foo = Table('foo', meta,
Column('somecol', NUMERIC(length=5, precision=2)),
Column('othercol', NUMERIC(length=8, precision=0)),
)
Then this is what could be expected (first param is always precision, right? ...
while NUMERIC can be used as synonyms for DECIMAL):
CREATE TABLE foo (
somecol NUMERIC(2, 5),
othercol NUMERIC(0,8)
)
According to DB2 Info Center documentation (see CREATE TABLE):
"DECIMAL(precision-integer, scale-integer) or DEC(precision-integer,
scale-integer)
For a decimal number. The first integer is the precision of the number; that is,
the total number of digits; it may range from 1 to 31. The second integer is the
scale of the number; that is, the number of digits to the right of the decimal
point;
it may range from 0 to the precision of the number.
If precision and scale are not specified, the default values of 5,0 are used. The
words NUMERIC and NUM can be used as synonyms for DECIMAL and DEC."
Original comment by apiti...@ca.ibm.com
on 7 Mar 2008 at 7:22
[deleted comment]
Florian, if this is what's expected:
CREATE TABLE foo (
somecol NUMERIC(5, 2),
othercol NUMERIC(8,0)
)
This is what works:
>>> import ibm_db_sa.ibm_db_sa
>>> db2 =
sqlalchemy.create_engine('ibm_db_sa://dude:almighty@great.server.com:50000/pydev
')
>>> metadata = MetaData()
>>> foo = Table('foo', metadata,
... Column('somecol', NUMERIC(precision=5, length=2)),
... Column('othercol', NUMERIC(precision=8, length=0)),
... )
>>> metadata.bind = db2
>>> metadata.create_all()
>>> users_table = Table('users', metadata, autoload=True, autoload_with=db2)
>>> users_table
Table('users',
MetaData(Engine(ibm_db_sa://dude:almighty@great.server.com:50000/pydev)),
Column('user_id', IBM_DBInteger(), table=<users>, primary_key=True,
nullable=False),
Column('user_name', IBM_DBString(length=None, convert_unicode=False,
assert_unicode=None), table=<users>, nullable=False), Column('email_address',
IBM_DBString(length=None, convert_unicode=False, assert_unicode=None),
table=<users>), Column('password', IBM_DBString(length=None,
convert_unicode=False,
assert_unicode=None), table=<users>, nullable=False), schema=None)
And I think the confusion is w/r to DB2 precision being under length column
db2 => describe table foo
Data type Column
Column name schema Data type name Length Scale
Nulls
------------------------------- --------- ------------------- ---------- -----
------
SOMECOL SYSIBM DECIMAL 5 2
Yes
OTHERCOL SYSIBM DECIMAL 8 0
Yes
Please let me know if you still believe there's an issue here. Thanks.
Original comment by apiti...@ca.ibm.com
on 7 Mar 2008 at 7:38
Original issue reported on code.google.com by
pyalot@gmail.com
on 5 Mar 2008 at 11:05