Hi,

I believe SQLAlchemy's behavior when creating primary_key integer
columns is incorrect, at least against PostgreSQL, but before opening a
ticket I'd like to hear what others think about it.

If you define a column as Integer or SmallInteger (Smallinteger) and
primary_key=True, SA assumes it requires an associated SQL sequence,
i.e., a SERIAL (or auto-increment) datatype.  In fact, in the latter
case, it overrides the SmallInteger specification and creates an Integer
column because (at least in PG) SERIAL implies INTEGER.

I have at least two tables in an existing database that have SMALLINT
primary keys and the values are *not* sequential (one of them is a
calendar year and not all years are logged in the table, the other has
arbitrary codes).  I also have a table that is one-to-one with the
principal table (which does have a SERIAL key), but for operational
reasons (it keeps track of activity against the other) it's kept
separate from it, so it's INTEGER primary key does not have an
associated sequence (except by derivation).

I don't think my examples are unique.  I'm pretty sure there are many
systems where identifiers are assigned non-sequentially, e.g., bank
account numbers with check digits.  Granted that these will tend to be
legacy systems, but I thought SA was supposed to cater to those.

Joe


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to