summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 312ae9aa8..72251c8d5 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -1006,6 +1006,27 @@ class PGDialect(default.DefaultDialect):
return primary_keys
@reflection.cache
+ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
+ cols = self.get_primary_keys(connection, table_name, schema=schema, **kw)
+
+ table_oid = self.get_table_oid(connection, table_name, schema,
+ info_cache=kw.get('info_cache'))
+
+ PK_CONS_SQL = """
+ SELECT conname
+ FROM pg_catalog.pg_constraint r
+ WHERE r.conrelid = :table_oid AND r.contype = 'p'
+ ORDER BY 1
+ """
+ t = sql.text(PK_CONS_SQL, typemap={'conname':sqltypes.Unicode})
+ c = connection.execute(t, table_oid=table_oid)
+ name = c.scalar()
+ return {
+ 'constrained_columns':cols,
+ 'name':name
+ }
+
+ @reflection.cache
def get_foreign_keys(self, connection, table_name, schema=None, **kw):
preparer = self.identifier_preparer
table_oid = self.get_table_oid(connection, table_name, schema,