From: Mark Huang Date: Mon, 25 Sep 2006 15:12:20 +0000 (+0000) Subject: - add fields() function for returning the column names of the specified X-Git-Tag: pycurl-7_13_1~711 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=4104c224401c26638b0be7ac0d9447fbbc25cc2c;p=plcapi.git - add fields() function for returning the column names of the specified table --- diff --git a/PLC/PostgreSQL.py b/PLC/PostgreSQL.py index 83768043..9eff5849 100644 --- a/PLC/PostgreSQL.py +++ b/PLC/PostgreSQL.py @@ -5,7 +5,7 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ +# $Id: PostgreSQL.py,v 1.1 2006/09/06 15:36:07 mlhuang Exp $ # import pgdb @@ -133,3 +133,16 @@ class PostgreSQL: return dict([(row[key_field], row) for row in rows]) else: return rows + + def fields(self, table): + """ + Return the names of the fields of the specified table. + """ + + rows = self.selectall("SELECT attname FROM pg_attribute, pg_class" \ + " WHERE pg_class.oid = attrelid" \ + " AND attnum > 0 AND relname = %(table)s", + locals(), + hashref = False) + + return [row[0] for row in rows]