summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-08-25 12:28:47 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-08-25 12:29:22 -0400
commit2452c49cc4d2244d0efef78e051eb65f79b7c712 (patch)
treef06a29dfe45e28861a3f05df2ae7530bf01bc9d2 /lib/sqlalchemy/sql
parentb3aa03853fcbc35d930de953b51f9e2fe5ba3def (diff)
downloadsqlalchemy-2452c49cc4d2244d0efef78e051eb65f79b7c712.tar.gz
added "system=True" to Column, so that we generally don't have to bother
with CreateColumn rules
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py3
-rw-r--r--lib/sqlalchemy/sql/ddl.py15
-rw-r--r--lib/sqlalchemy/sql/schema.py13
3 files changed, 26 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index c56ca1ae4..6370b1227 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2205,6 +2205,9 @@ class DDLCompiler(Compiled):
def visit_create_column(self, create, first_pk=False):
column = create.element
+ if column.system:
+ return None
+
text = self.get_column_specification(
column,
first_pk=first_pk
diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py
index a0163ad7a..a17c8ee53 100644
--- a/lib/sqlalchemy/sql/ddl.py
+++ b/lib/sqlalchemy/sql/ddl.py
@@ -551,13 +551,18 @@ class CreateColumn(_DDLCompiles):
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``::
+ This is essentially how to produce the same effect as using the
+ ``system=True`` argument on :class:`.Column`, which marks a column
+ as an implicitly-present "system" column.
+
+ For example, suppose we wish to produce a :class:`.Table` which skips
+ rendering of the Postgresql ``xmin`` column against the Postgresql backend,
+ but on other backends does render it, in anticipation of a triggered rule.
+ A conditional compilation rule could skip this name only on Postgresql::
from sqlalchemy.schema import CreateColumn
- @compiles(CreateColumn)
+ @compiles(CreateColumn, "postgresql")
def skip_xmin(element, compiler, **kw):
if element.element.name == 'xmin':
return None
@@ -572,7 +577,7 @@ class CreateColumn(_DDLCompiles):
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.
+ will be omitted, but only against the Postgresql backend.
.. versionadded:: 0.8.3 The :class:`.CreateColumn` construct supports
skipping of columns by returning ``None`` from a custom compilation rule.
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index ce4182c54..5930df124 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -893,6 +893,18 @@ class Column(SchemaItem, ColumnClause):
an explicit name, use the :class:`.UniqueConstraint` or
:class:`.Index` constructs explicitly.
+ :param system: When ``True``, indicates this is a "system" column,
+ that is a column which is automatically made available by the
+ database, and should not be included in the columns list for a
+ ``CREATE TABLE`` statement.
+
+ For more elaborate scenarios where columns should be conditionally
+ rendered differently on different backends, consider custom
+ compilation rules for :class:`.CreateColumn`.
+
+ ..versionadded:: 0.8.3 Added the ``system=True`` parameter to
+ :class:`.Column`.
+
"""
name = kwargs.pop('name', None)
@@ -922,6 +934,7 @@ class Column(SchemaItem, ColumnClause):
self.server_onupdate = kwargs.pop('server_onupdate', None)
self.index = kwargs.pop('index', None)
self.unique = kwargs.pop('unique', None)
+ self.system = kwargs.pop('system', False)
self.quote = kwargs.pop('quote', None)
self.doc = kwargs.pop('doc', None)
self.onupdate = kwargs.pop('onupdate', None)