diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2020-03-14 13:57:42 +0100 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-15 19:09:04 -0400 |
| commit | 62b7dace0c1d03acf3224085d03a03684a969031 (patch) | |
| tree | 29037c928ce0b5b728a5d7ba2eb24ac6f110664c /lib/sqlalchemy/engine/reflection.py | |
| parent | fcc03730c553b3fc0229e446e886d4f61dcb6291 (diff) | |
| download | sqlalchemy-62b7dace0c1d03acf3224085d03a03684a969031.tar.gz | |
Support inspection of computed column
Added support for reflection of "computed" columns, which are now returned
as part of the structure returned by :meth:`.Inspector.get_columns`.
When reflecting full :class:`.Table` objects, computed columns will
be represented using the :class:`.Computed` construct.
Also improve the documentation in :meth:`Inspector.get_columns`, correctly
listing all the returned keys.
Fixes: #5063
Fixes: #4051
Closes: #5064
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5064
Pull-request-sha: ba00fc321ce468f8885aad23b3dd33c789e50fbe
Change-Id: I789986554fc8ac7f084270474d0b2c12046b1cc2
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
| -rw-r--r-- | lib/sqlalchemy/engine/reflection.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index 25538fddb..ba60d634e 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -419,7 +419,26 @@ class Inspector(object): * ``default`` - the column's server default value - this is returned as a string SQL expression. - * ``attrs`` - dict containing optional column attributes + * ``autoincrement`` - indicates that the column is auto incremented - + this is returned as a boolean or 'auto' + + * ``comment`` - (optional) the commnet on the column. Only some + dialects return this key + + * ``computed`` - (optional) when present it indicates that this column + is computed by the database. Only some dialects return this key. + Returned as a dict with the keys: + + * ``sqltext`` - the expression used to generate this column returned + as a string SQL expression + + * ``persisted`` - (optional) boolean that indicates if the column is + stored in the table + + .. versionadded:: 1.3.16 - added support for computed reflection. + + * ``dialect_options`` - (optional) a dict with dialect specific options + :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. @@ -825,6 +844,10 @@ class Inspector(object): colargs.append(default) + if "computed" in col_d: + computed = sa_schema.Computed(**col_d["computed"]) + colargs.append(computed) + if "sequence" in col_d: self._reflect_col_sequence(col_d, colargs) |
