Postgres "double precision" type is generates error if autoloading a table.

Issue #416 resolved
Former user created an issue

Try the following:

Create a table in postgres that has a 'float' value:

CREATE TABLE foo (value float);

No run the following script:

from sqlalchemy import *
metadata = BoundMetaData("postgres://guest@localhost/mydatabase")
b = Table("foo", metadata, autoload=1)

If you run this you will get the following error:

Traceback (most recent call last):
  File "t.py", line 3, in <module>
    b = Table("foo", metadata, autoload=1)
  File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 143, in __call__
  File "build/bdist.linux-i686/egg/sqlalchemy/engine/base.py", line 505, in reflecttable
  File "build/bdist.linux-i686/egg/sqlalchemy/databases/postgres.py", line 386, in reflecttable

The reason is that PGFloat inherits from Float which takes on one argument in its constructor.

The following patch fixes that:

Index: lib/sqlalchemy/databases/postgres.py
===================================================================
--- lib/sqlalchemy/databases/postgres.py        (revision 2193)
+++ lib/sqlalchemy/databases/postgres.py        (working copy)
@@ -371,7 +371,8 @@
                 args = []
                 for a in (charlen, numericprec, numericscale):
                     if a is None:
-                        args.append(None)
+                        if attype != 'double precision':
+                            args.append(None)
                     elif a is not False:
                         args.append(int(a))

Comments (3)

  1. Mike Bayer repo owner

    cant reproduce. i ran exactly your test, and added a "print for c in b.c" and i get:

    [Column('value',PGFloat(precision=53))](Column('value',PGFloat(precision=53)))

    also, you arent showing me the actual error youre getting, thats not a complete stack trace (and also line 386, both in rev 2193 and the head, just create blank dictionaries/lists so that is a little weird).

  2. Log in to comment