Re: Error with ALTER TABLE %s

"Karsten Hilbert" <[email protected]> Tue, 04 May 2010 22:37:31 +0200
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
> > Right, so for posterity's sake, the OP should just use this:
> >    cur.execute(SQL % data)
> 
> And one last bit for the archives:
> If you want/need to use a reserved keyword or preserve MixedCase for a
> identifier, it can be quoted, with double-quotes:
> 
> >>> data=('"MixedCase"',)
> >>> SQL % data
> 'ALTER TABLE films ADD COLUMN ("MixedCase") text;'
> 
> Not that I'd recommend that. Had an interface do that to me many years
> ago. Made building manual queries a painful process:
> 
> SELECT "MyColumn" from "MyTable" join "MyOtherTable" where
> "MyTable"."MyId" == "MyOtherTable"."ParentId" ...

Maybe the PostgreSQL function

   quote_ident()

   (http://www.postgresql.org/docs/9.0/static/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE)

might be useful in getting it right ?

Karsten
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01