how to handle SQLite's GUID?

16 views
Skip to first unread message

c.b...@posteo.jp

unread,
Mar 9, 2016, 7:11:30 PM3/9/16
to sqlalchemy
What would be the best and most save way to represent the "GUID PRIMARY
KEY" column type from SQLite3 in a SQLAlchemy schema?

The SQL looks like this

CREATE TABLE Reference (ID GUID CONSTRAINT PK_Reference PRIMARY KEY, ...

The DB ist foreign and not created by me.

Mike Bayer

unread,
Mar 10, 2016, 9:35:53 AM3/10/16
to sqlal...@googlegroups.com
from sqlalchemy import *
from sqlalchemy.types import UserDefinedType


class GUID(UserDefinedType):
def get_col_spec(self, **kw):
return "GUID"

e = create_engine("sqlite://", echo=True)

m = MetaData()
t = Table(
't', m,
Column('id', GUID),
PrimaryKeyConstraint('id', name="PkReference")
)
m.create_all(e)



output:

CREATE TABLE t (
id GUID NOT NULL,
CONSTRAINT "PkReference" PRIMARY KEY (id)
)

c.b...@posteo.jp

unread,
Mar 10, 2016, 5:14:33 PM3/10/16
to sqlal...@googlegroups.com
Ok, sorry. I used unconcrete words.

I don't want to create something like that.

I want to know which one of the standard SQLAlchemy-offered data types
would be the best fitting to handle (just read and use for UPDATE) a
vendor-column-type like that.
Reply all
Reply to author
Forward
0 new messages