Re: SELECT from mytbl; - Mailing list pgsql-general

From PFC
Subject Re: SELECT from mytbl;
Date
Msg-id op.ts4ks3mrcigqcu@apollo13
Whole thread Raw
In response to Re: SELECT from mytbl;  (Erwin Brandstetter <brsaweda@gmail.com>)
Responses Re: SELECT from mytbl;
List pgsql-general
On Wed, 30 May 2007 05:24:57 +0200, Erwin Brandstetter
<brsaweda@gmail.com> wrote:

> On May 30, 2:11 am, Rodrigo De León <rdele...@gmail.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



pgsql-general by date:

Previous
From: Erwin Brandstetter
Date:
Subject: Re: SELECT from mytbl;
Next
From: "Albe Laurenz"
Date:
Subject: Re: hundreds of schema vs hundreds of databases