[Tutor] postgreSQL + psycopg2
Peter Otten
__peter__ at web.de
Mon May 9 17:45:29 EDT 2016
nitin chandra wrote:
> Hi All,
>
> I am trying to pass a variable to the following statement :
>
> for line1 in smallLIST1:
> design1 = line1[3]
> print design1
> nextRow=cursor1.execute("SELECT designation_name FROM designation
> WHERE designation_id = %s;", (design1))
Note that in the expression
(design1)
the parens have no effect:
>>> design1 = 42
>>> (design1)
42
To get a 1-tuple add a comma:
>>> (design1,)
(42,)
> print nextRow
> print """<tr>"""
> for row in line1:
> print """<td>"""+str(row)+"""</td>"""
> print """</tr>"""
>
> 1st "print" shows values 1 , correctly.
> 2nd "print" shows "None".
>
> I am not able to pass this value, 1, as variable to the SELECT statement.
>
> the following is 'line1'
>
> (1, 'Vinayak', 'Salunke', '1', datetime.date(1982, 6, 6), 9871234567L,
> 'Tower-1,Millinium tower', 0, 1, datetime.date(2016, 5, 6),
> datetime.datetime(2016, 5, 6, 22, 55, 5,
> tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=330, name=None)))
>
>
> On postgreSQL command this works
>
> SELECT designation_name FROM designation WHERE designation_id = 1;
>
> Python 2.7.6, Postgresql 9.3.7, psycopg2, apache & cgi.
>
> A little help.
>
> Thanks
>
> Nitin
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list