[BangPypers] psycopg2 problem
JAGANADH G
jaganadhg at gmail.com
Mon Oct 26 12:41:59 CET 2009
On Mon, Oct 26, 2009 at 5:04 PM, Anand Chitipothu <anandology at gmail.com>wrote:
> On Mon, Oct 26, 2009 at 5:00 PM, JAGANADH G <jaganadhg at gmail.com> wrote:
> > On Mon, Oct 26, 2009 at 4:46 PM, Anand Chitipothu <anandology at gmail.com
> >wrote:
> >
> >> > I was trying to connect to postgre db with Python psycopg2 . The code
> for
> >> > connecting the db is
> >> >
> >> > import psycopg2
> >> >
> >> > try:
> >> > dbconn = psycopg2.connect( "dbname=%s user=%s\
> >> > host='localhost' password=%s" ) % ( dbname,dbuser, dbpass )
> >> > except:
> >> > raise
> >>
> >> You are trying to pass all db parameters. You should be doing some
> >> thing like this:
> >>
> >> conn = psycopg2.connect(dbname=dbname, user=dbuser, password=dbpass)
> >>
> >> Anand
> >>
> >
> > Now I did it . The code will be now
> >
> > dbcs = "dbname=%s user=%s host='localhost' password=%s" %(dbname,
> > dbuser,dbpass)
>
> It is not same. You are trying to creating one string and pass that
> string as argument to connect. But I passed 3 different parameters.
>
> f(1, 2) is not same as f("1 2").
>
>
Right .
Any how I am facing new problem now. See the error. Any hint ?
dbcursor.execute( "SELECT id,text FROM %s " ) % indbtname
psycopg2.ProgrammingError: syntax error at or near "%"
LINE 1: SELECT id,text FROM %s
--
**********************************
JAGANADH G
http://jaganadhg.freeflux.net/blog
Sent from Chennai, TN, India
More information about the BangPypers
mailing list