On Wed, 30 May 2007 05:24:57 +0200, Erwin Brandstetter <[EMAIL PROTECTED]> wrote:

On May 30, 2:11 am, Rodrigo De León <[EMAIL PROTECTED]> wrote:
(... useful code example snipped)

Now see:

http://www.postgresql.org/docs/8.2/static/plpgsql-control-structures....

Thanks for your hints, Rodrigo!
I am aware I can consult pg_catalog / information_schema to retrieve
the information, but that's not quite the "short way" I was hoping
for. Your example is still helpful, though. :)


        Python example :

import psycopg2
db = psycopg2.connect( host='/var/run/postgresql', user='annonces', database='annonces' )
cursor = db.cursor()

bad = set(('email','website','comment'))

cursor.execute( "SELECT * FROM contacts LIMIT 0" )

fields = [d[0] for d in cursor.description]
print fields
['id', 'name', 'person', 'telephone', 'address', 'zipcode', 'city', 'fax', 'email', 'website', 'comment', 'group_id', 'name_search', 'address_search']

print "SELECT "+(','.join([d for d in fields if d not in bad]))+" FROM contacts"
SELECT id,name,person,telephone,address,zipcode,city,fax,group_id,name_search,address_search FROM contacts

print "SELECT " + (','.join(set(fields).difference(bad)))+ " FROM contacts"
SELECT city,fax,name_search,name,zipcode,telephone,person,address_search,address,group_id,id FROM contacts









Regards
Erwin




---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to