Creating column comments on the database

985 views
Skip to first unread message

Christoph Zwerschke

unread,
Jun 4, 2008, 8:41:06 AM6/4/08
to sqlal...@googlegroups.com
Does SQLAlchemy support "comment on column" or comments on other
database objects? I expected Column to have a comment keyword, but found
nothing of that kind. Maybe I am missing something?

I find column comments often useful, and though they may not be SQL
standard, they are supported by all major databases.

-- Christoph

Michael Bayer

unread,
Jun 4, 2008, 10:40:00 AM6/4/08
to sqlal...@googlegroups.com
at the very least you could use per-table DDL() with an "ALTER" to
apply it after the fact...

Lukasz Szybalski

unread,
Jun 4, 2008, 11:11:15 AM6/4/08
to sqlal...@googlegroups.com

I started using info dict on a column names in sa file definitions. It
would be nice to save it to db if once could. What db supports
comments and what table name is it?

Lucas

Christoph Zwerschke

unread,
Jun 4, 2008, 1:09:10 PM6/4/08
to sqlal...@googlegroups.com
Lukasz Szybalski schrieb:

> I started using info dict on a column names in sa file definitions. It
> would be nice to save it to db if once could. What db supports
> comments and what table name is it?

Oracle and PostgreSQL have the "comment on" SQL statement. MySQL has a
comment clause for column definitions. SA could abstract away these
differences, the syntax would be something like this:

users = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(40), comment="The Unix user name"),
Column('fullname', String(100), comment="Full name with title"))

This way, the table definition in Python itself would be commented, and
at the same time, comments on the database would be created that help
you if you operate directly on the database with some admin tool.

-- Christoph

Lukasz Szybalski

unread,
Jun 4, 2008, 1:18:23 PM6/4/08
to sqlal...@googlegroups.com
On Wed, Jun 4, 2008 at 12:09 PM, Christoph Zwerschke <ci...@online.de> wrote:
>
> Lukasz Szybalski schrieb:
>> I started using info dict on a column names in sa file definitions. It
>> would be nice to save it to db if once could. What db supports
>> comments and what table name is it?
>
> Oracle and PostgreSQL have the "comment on" SQL statement. MySQL has a
> comment clause for column definitions. SA could abstract away these
> differences, the syntax would be something like this:
>
> users = Table('users', metadata,
> Column('id', Integer, primary_key=True),
> Column('name', String(40), comment="The Unix user name"),
> Column('fullname', String(100), comment="Full name with title"))

I think I prefer "info" dictionary rather then a string. Dict "info"
which I use already have something like this:

sqlalchemy.Column('DRIVE_TRAIN', sqlalchemy.Unicode(4)
,info={"description":"DRIVE TRAIN TYPE [AWD,4WD,FWD,RWD]"}),
sqlalchemy.Column('FUEL_SYS', sqlalchemy.Unicode(4)
,info={"description":"FUEL SYSTEM CODE",
"FI":"FUEL INJECTION",
"TB":"TURBO"}),

Would be nice if the whole dictionary was written to a database. I
could use info[description], info[FI], info[TB] etc... when I display
data. That would be really useful definition!!!

Lucas

Christoph Zwerschke

unread,
Jun 5, 2008, 3:37:21 AM6/5/08
to sqlal...@googlegroups.com
Lukasz Szybalski schrieb:

> I think I prefer "info" dictionary rather then a string. Dict "info"
> which I use already have something like this:
>
> sqlalchemy.Column('DRIVE_TRAIN', sqlalchemy.Unicode(4)
> ,info={"description":"DRIVE TRAIN TYPE [AWD,4WD,FWD,RWD]"}),
> sqlalchemy.Column('FUEL_SYS', sqlalchemy.Unicode(4)
> ,info={"description":"FUEL SYSTEM CODE",
> "FI":"FUEL INJECTION",
> "TB":"TURBO"}),

I think you're mixing different things here. What I suggested was
support of the database comment statement/clause supported by all major
databases (except maybe SQL Server).

What you're looking for seems to be something similar to the "Domain"
feature of the old Oracle Designer,

http://marceloverdijk.blogspot.com/2008/05/ref-code-plugin.html
http://its.unm.edu/ais/docs/oradomains.htm

This would be an interesting extension as well. Should be possible with
a custom TypeDecorator or TypeEngine.

-- Christoph

Lukasz Szybalski

unread,
Jun 5, 2008, 10:08:14 AM6/5/08
to sqlal...@googlegroups.com
On Thu, Jun 5, 2008 at 2:37 AM, Christoph Zwerschke <ci...@online.de> wrote:
>
> Lukasz Szybalski schrieb:
>> I think I prefer "info" dictionary rather then a string. Dict "info"
>> which I use already have something like this:
>>
>> sqlalchemy.Column('DRIVE_TRAIN', sqlalchemy.Unicode(4)
>> ,info={"description":"DRIVE TRAIN TYPE [AWD,4WD,FWD,RWD]"}),
>> sqlalchemy.Column('FUEL_SYS', sqlalchemy.Unicode(4)
>> ,info={"description":"FUEL SYSTEM CODE",
>> "FI":"FUEL INJECTION",
>> "TB":"TURBO"}),
>
> I think you're mixing different things here. What I suggested was
> support of the database comment statement/clause supported by all major
> databases (except maybe SQL Server).

I see.

>
> What you're looking for seems to be something similar to the "Domain"
> feature of the old Oracle Designer,

I wonder if it was possible to save the info field "{}" I showed above
via the comment statement/clause you are mentioning if it gets
implemented?

This would really help in describing business rules and descriptions
of each column.
Lucas


>
> http://marceloverdijk.blogspot.com/2008/05/ref-code-plugin.html
> http://its.unm.edu/ais/docs/oradomains.htm
>
> This would be an interesting extension as well. Should be possible with
> a custom TypeDecorator or TypeEngine.
>
> -- Christoph
>
> >
>

--
Automotive Recall Database. Cars, Trucks, etc.
http://www.lucasmanual.com/recall/
TurboGears Manual-Howto
http://lucasmanual.com/pdf/TurboGears-Manual-Howto.pdf

Reply all
Reply to author
Forward
0 new messages