On Nov 26, 2012, at 2:51 AM, txnaidaa_sqlalchemy wrote:

> Hi all,
> 
> I have noticed that the DECIMAL type is not rendered with precision or scale:
> 
>>>> sa.__version__
>    '0.7.9'
>>>> import sqlalchemy as sa
>>>> print sa.NUMERIC(6, 4)
>    NUMERIC(6, 4)
>>>> print sa.DECIMAL(6, 4)
>    DECIMAL
> 
> This causes problems in eg alembic where a table definition that uses 
> DECIMAL(x, y) will silently lose the scale and precision eg an upgrade script 
> such as 
> 
>    def upgrade():
>        op.create_table("x",
>            sa.Column("x", sa.DECIMAL(6, 4)))
> 
> produces:
> 
>    CREATE TABLE x (
>        x DECIMAL NULL
>    );
> 
> To have precision you must use the NUMERIC type.
> 
> I'm mainly encountering this issue when generating the sql for an existing 
> database where I reflect the metadata and then issue a create_all via a mock 
> engine ... it then renders all of the DECIMAL columns in the existing model 
> (that I have no control over) without their scale or precision.
> 
> Is there a reason for this or is it a bug?  Currently I am monkey patching 
> sqlalchemy.sql.compiler.GenericTypeCompiler.visit_DECIMAL in order to get 
> what I view as "correct" output.

which platform allows for DECIMAL with scale and precision?  the ultimate fix 
would be to supply the appropriate type compilation to the target backend.

also no monkeypatching required, please see 
http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#overriding-type-compilation


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to