summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
diff options
context:
space:
mode:
authorFrazer McLean <frazer@frazermclean.co.uk>2016-06-13 10:31:18 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-13 10:31:18 -0400
commit84974cf09220105bc7a92e5bcde31f52827c1de7 (patch)
tree250677d68a0c6ba0070a97cd6cd3a7c2c2949c50 /lib/sqlalchemy/dialects/postgresql
parent7189d0bc82598c2d6dcbb55b054837416db2ee7d (diff)
downloadsqlalchemy-pr_github_284.tar.gz
Comment supportpr_github_284
Implementation of [#1546 (BitBucket)](https://bitbucket.org/zzzeek/sqlalchemy/issues/1546). Very unfinished but I have reflection and setting after table creation working for PostgreSQL. If you're not opposed, perhaps best to continue discussion on Gerrit? Change-Id: Ib90683850805a2b4ee198e420dc294f32f15d35d Pull-request: https://github.com/zzzeek/sqlalchemy/pull/284
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 16b22129a..3c111e3cc 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -2057,8 +2057,11 @@ class PGDialect(default.DefaultDialect):
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum
AND a.atthasdef)
AS DEFAULT,
- a.attnotnull, a.attnum, a.attrelid as table_oid
+ a.attnotnull, a.attnum, a.attrelid as table_oid,
+ pgd.description as comment
FROM pg_catalog.pg_attribute a
+ LEFT JOIN pg_catalog.pg_description pgd ON (
+ pgd.objoid = a.attrelid AND pgd.objsubid = a.attnum)
WHERE a.attrelid = :table_oid
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
@@ -2082,14 +2085,16 @@ class PGDialect(default.DefaultDialect):
# format columns
columns = []
- for name, format_type, default, notnull, attnum, table_oid in rows:
+ for name, format_type, default, notnull, attnum, table_oid, \
+ comment in rows:
column_info = self._get_column_info(
- name, format_type, default, notnull, domains, enums, schema)
+ name, format_type, default, notnull, domains, enums,
+ schema, comment)
columns.append(column_info)
return columns
def _get_column_info(self, name, format_type, default,
- notnull, domains, enums, schema):
+ notnull, domains, enums, schema, comment):
# strip (*) from character varying(5), timestamp(5)
# with time zone, geometry(POLYGON), etc.
attype = re.sub(r'\(.*\)', '', format_type)
@@ -2196,7 +2201,8 @@ class PGDialect(default.DefaultDialect):
match.group(2) + match.group(3)
column_info = dict(name=name, type=coltype, nullable=nullable,
- default=default, autoincrement=autoincrement)
+ default=default, autoincrement=autoincrement,
+ comment=comment)
return column_info
@reflection.cache
@@ -2528,6 +2534,24 @@ class PGDialect(default.DefaultDialect):
]
@reflection.cache
+ def get_table_comment(self, connection, table_name, schema=None, **kw):
+ table_oid = self.get_table_oid(connection, table_name, schema,
+ info_cache=kw.get('info_cache'))
+
+ COMMENT_SQL = """
+ SELECT
+ pgd.description as table_comment
+ FROM
+ pg_catalog.pg_description pgd
+ WHERE
+ pgd.objsubid = 0 AND
+ pgd.objoid = :table_oid
+ """
+
+ c = connection.execute(sql.text(COMMENT_SQL), table_oid=table_oid)
+ return c.scalar()
+
+ @reflection.cache
def get_check_constraints(
self, connection, table_name, schema=None, **kw):
table_oid = self.get_table_oid(connection, table_name, schema,