TypeDecorator class as primary key

14 views
Skip to first unread message

warp

unread,
Apr 10, 2009, 3:29:51 PM4/10/09
to sqlalchemy
Hello,

I wanted to use a custom type as an auto-increment / primary key in
one of my
tables. The type is made like this:

class BoxId (sqlalchemy.types.TypeDecorator):
impl = sqlalchemy.types.Integer

Using it in a table like this:

box = Table ('box', metadata,
Column ('id', BoxId, primary_key=True),
Column ('catalog', Unicode(64)),
)

But having the table defined like that raises an exception when trying
to insert
values. I'm using postgres and it looks like
sqlalchemy.databases.postgres.PGDefaultRunner.get_column_default ()
deals
with auto-increments and is specifically looking for an
sqlalchemy.types.Integer.
I expected sqlalchemy would treat a type created the way I did above
more or less
like an integer, because of the impl attribute.

Is this a bug in either sqlalchemy or specifically the postgres part?
Or is this just
not supposed to work like this? (I'm fairly new to sqlalchemy :)

Thank you for any help you can give me.

-- Kuno.

Michael Bayer

unread,
Apr 10, 2009, 4:45:45 PM4/10/09
to sqlal...@googlegroups.com

the "Integer" detection should probably detect the "Integer" ness of the
column, but for now you can just define the sequence explicitly:

Column('mycolumn', MyType, Sequence('mycolumn_id_seq'), primary_key=True)


Kuno Woudt

unread,
Apr 11, 2009, 6:59:16 AM4/11/09
to sqlal...@googlegroups.com
On Fri, Apr 10, 2009 at 04:45:45PM -0400, Michael Bayer wrote:
>
> warp wrote:

[snip]

> > I expected sqlalchemy would treat a type created the way I did above
> > more or less like an integer, because of the impl attribute.

[snip]



> the "Integer" detection should probably detect the "Integer" ness of the
> column, but for now you can just define the sequence explicitly:
>
> Column('mycolumn', MyType, Sequence('mycolumn_id_seq'), primary_key=True)

Awesome, this solves my problem. thanks again.

-- kuno.

Reply all
Reply to author
Forward
0 new messages