From: <gdr...@ya...> - 2003-08-27 22:16:15
|
--- Jorge Godoy <go...@ie...> escribió: > > Hi. > > > I have to feed a database with several hundred > entries and I am > importing all those with PostgreSQL's 'COPY <table> > FROM <file>' > command. It works great when I'm using my superuser > but it fails for > any other user with a message specifying that I > should either: > > * use my superuser > * make these users superuser > * or use 'stdin' (this is the recommendation on > the error message) > as source for my input. > > Since I can't make other superusers (there are > several other databases > there that should be protected from common > employees) I was trying to > use stdin as data source. > > Anybody has tried it? I don't know how to > concatenate the thousands of > lines from the output of a 'file.readlines()' (or > something like that) > to my cursor.execute() command. Using something like > "cursor.execute(query_sql, file.readlines())" didn't > work and gave me > an error message saying 'not all arguments > converted' (query_sql is > the copy from command). Hello: Try this idea. mycursor.execute('copy '+table+' from stdin;') lines=file.read() for n in lines: mycursor.conn.conn.putline(n) mycursor.conn.conn.putline('\\.\n') #end of insertion mycursor.conn.conn.endcopy() myconnection.commit() #to make insertions available _________________________________________________________ Do You Yahoo!? Información de Estados Unidos y América Latina, en Yahoo! Noticias. Visítanos en http://noticias.espanol.yahoo.com |