diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-08-24 13:55:14 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-08-24 13:56:01 -0400 |
commit | e9b2e33f15cd74978ca858e768e9c44abb1d00f3 (patch) | |
tree | 80ed08ecb49907f916f9b45f7a909f32058f1233 /lib/sqlalchemy/sql/ddl.py | |
parent | 460b23731cba29d319f0e9a3bc5b6df518c9df73 (diff) | |
download | sqlalchemy-e9b2e33f15cd74978ca858e768e9c44abb1d00f3.tar.gz |
- The :class:`.CreateColumn` construct can be appled to a custom
compilation rule which allows skipping of columns, by producing
a rule that returns ``None``. Also in 0.8.3.
Diffstat (limited to 'lib/sqlalchemy/sql/ddl.py')
-rw-r--r-- | lib/sqlalchemy/sql/ddl.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py index 8159ca472..a0163ad7a 100644 --- a/lib/sqlalchemy/sql/ddl.py +++ b/lib/sqlalchemy/sql/ddl.py @@ -548,6 +548,35 @@ class CreateColumn(_DDLCompiles): PRIMARY KEY (x) ) + The :class:`.CreateColumn` construct can also be used to skip certain + columns when producing a ``CREATE TABLE``. This is accomplished by + creating a compilation rule that conditionally returns ``None``. + For example, to produce a + :class:`.Table` which includes the Postgresql system column ``xmin``, + but omits this column from the ``CREATE TABLE``:: + + from sqlalchemy.schema import CreateColumn + + @compiles(CreateColumn) + def skip_xmin(element, compiler, **kw): + if element.element.name == 'xmin': + return None + else: + return compiler.visit_create_column(element, **kw) + + + my_table = Table('mytable', metadata, + Column('id', Integer, primary_key=True), + Column('xmin', Integer) + ) + + Above, a :class:`.CreateTable` construct will generate a ``CREATE TABLE`` + which only includes the ``id`` column in the string; the ``xmin`` column + will be omitted. + + .. versionadded:: 0.8.3 The :class:`.CreateColumn` construct supports + skipping of columns by returning ``None`` from a custom compilation rule. + .. versionadded:: 0.8 The :class:`.CreateColumn` construct was added to support custom column creation styles. |