pgtoolkit/pgbrowser.py
changeset 12 203be9022b46
parent 9 2fcc8ef0b97d
child 31 c2e6e24b83d9
equal deleted inserted replaced
11:bc69eca59041 12:203be9022b46
   206             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
   206             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
   207             WHERE n.nspname = %s AND c.relkind IN ('r','s','')
   207             WHERE n.nspname = %s AND c.relkind IN ('r','s','')
   208             ORDER BY 1;
   208             ORDER BY 1;
   209             ''', schema)
   209             ''', schema)
   210 
   210 
   211     def list_columns(self, table, schema='public'):
   211     def list_columns(self, table, schema='public', order=2):
   212         return self._query('''
   212         return self._query('''
   213             SELECT
   213             SELECT
       
   214                 a.attrelid,
   214                 a.attname as "name",
   215                 a.attname as "name",
   215                 format_type(a.atttypid, a.atttypmod) AS "type",
   216                 format_type(a.atttypid, a.atttypmod) AS "type",
   216                 a.attnotnull as "notnull",
   217                 a.attnotnull as "notnull",
   217                 a.atthasdef as "hasdefault",
   218                 a.atthasdef as "hasdefault",
   218                 d.adsrc as "default",
   219                 d.adsrc as "default",
   220             FROM pg_catalog.pg_attribute a
   221             FROM pg_catalog.pg_attribute a
   221             LEFT JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
   222             LEFT JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
   222             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
   223             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
   223             LEFT JOIN pg_catalog.pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
   224             LEFT JOIN pg_catalog.pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
   224             WHERE n.nspname = %s AND c.relname = %s AND a.attnum > 0 AND NOT a.attisdropped
   225             WHERE n.nspname = %s AND c.relname = %s AND a.attnum > 0 AND NOT a.attisdropped
   225             ORDER BY 1
   226             ORDER BY ''' + str(order), schema, table)
   226             ''', schema, table)
       
   227 
   227 
   228     def list_constraints(self, table, schema='public'):
   228     def list_constraints(self, table, schema='public'):
   229         return self._query('''
   229         return self._query('''
   230             SELECT
   230             SELECT
   231                 conname as "name",
   231                 conname as "name",