From: | PFC <lists(at)peufeu(dot)com> |
---|---|
To: | "Erwin Brandstetter" <brsaweda(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: SELECT <all fields except "bad_field"> from mytbl; |
Date: | 2007-05-30 05:42:29 |
Message-ID: | op.ts4ks3mrcigqcu@apollo13 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, 30 May 2007 05:24:57 +0200, Erwin Brandstetter
<brsaweda(at)gmail(dot)com> wrote:
> On May 30, 2:11 am, Rodrigo De León <rdele(dot)(dot)(dot)(at)gmail(dot)com> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Albe Laurenz | 2007-05-30 06:38:35 | Re: hundreds of schema vs hundreds of databases |
Previous Message | Erwin Brandstetter | 2007-05-30 05:28:09 | Re: SELECT <all fields except "bad_field"> from mytbl; |