[DB-SIG] Newbie: PyGreSQL and Insertion of random numbers
kromag@nsacom.net
kromag@nsacom.net
Wed, 11 Apr 2001 00:23:50 -0700 (PDT)
I am attempting to insert random numbers into a PostGreSQL database using _pg
and random. I am unsure as to syntax when adding variables.
I have attempted the following:
import _pg
import random
db.connect('test', 'localhost')
db.query("insert into pork values(`random.randint(1,1000)`+ 'stuff' +'1-2-
1999')")
which returns a parse error at the second opening parenthesis. (So a query
doesn't act like a string! I learned something!)
I have also attempted:
db.query("insert into pork values('`random.randint(1,1000)`', 'stuff', '1-2-
1999')")
which, of course inserts random.randint() as a literal string.
What am I doing wrong?