pgtoolkit/pgbrowser.py
changeset 32 d59c473c9ad7
parent 31 c2e6e24b83d9
child 35 e7f79c4a27ce
equal deleted inserted replaced
31:c2e6e24b83d9 32:d59c473c9ad7
   258             ''', {'schema': schema, 'table': table})
   258             ''', {'schema': schema, 'table': table})
   259 
   259 
   260     def list_column_usage(self, table, column, schema='public'):
   260     def list_column_usage(self, table, column, schema='public'):
   261         '''List objects using the column.
   261         '''List objects using the column.
   262         
   262         
   263         These objects may block alteration of column. Currently only views are listed.
   263         Currently shows views and constraints which use the column.
       
   264         
       
   265         This is useful to find which views block alteration of column type etc.
   264         
   266         
   265         '''
   267         '''
   266         return self._query('''
   268         return self._query('''
   267             SELECT
   269             SELECT
   268                 'view' AS type, view_schema AS schema, view_name AS name
   270                 'view' AS type, view_schema AS schema, view_name AS name
   269             FROM information_schema.view_column_usage
   271             FROM information_schema.view_column_usage
   270             WHERE table_schema=%(schema)s AND table_name=%(table)s AND column_name=%(column)s
   272             WHERE table_schema=%(schema)s AND table_name=%(table)s AND column_name=%(column)s
       
   273             
       
   274             UNION
       
   275             
       
   276             SELECT
       
   277                 'constraint' AS type, constraint_schema AS schema, constraint_name AS name
       
   278             FROM information_schema.constraint_column_usage
       
   279             WHERE table_schema=%(schema)s AND table_name=%(table)s AND column_name=%(column)s
   271             ''', {'schema':schema, 'table':table, 'column':column})
   280             ''', {'schema':schema, 'table':table, 'column':column})
   272 
   281