[Tutor] postgreSQL + psycopg2
Alan Gauld
alan.gauld at yahoo.co.uk
Mon May 9 19:06:57 EDT 2016
On 09/05/16 22:14, nitin chandra wrote:
> for line1 in smallLIST1:
> design1 = line1[3]
> print design1
> nextRow=cursor1.execute("SELECT designation_name FROM designation
> WHERE designation_id = %s;", (design1))
> print nextRow
> print """<tr>"""
> for row in line1:
> print """<td>"""+str(row)+"""</td>"""
> print """</tr>"""
>
> 1st "print" shows values 1 , correctly.
I assume you mean design1?
> 2nd "print" shows "None".
I don't know postgres API so i'll assume the %s is the correct
marker. In SQLite we'd use ?...
Also to get the results row by row I'd expect to have
to call fetchone() on the cursor:
query = """
SELECT designation_name
FROM designation
WHERE designation_id = %s;"""
nextrow = cursor1.execute(query, (design1,)).fetchone()
But Postgres DBAPI may be different...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list