Thread: Problem with strange chars in text filed.
I have a table:
create table truck (name varchar(45),address varchar(150));
doing an insert:
for i in range (0,10):
meme = fake.name()
address = fake.address()
print (meme,address)
cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", ([meme], [address]))
conn.commit()
Heres what the data looks like:
xcv=# select * from truck2;
name | address
-----------------------+------------------------------------
{"Hana Mosciski"} | {"9597 Rosalia Rue +
| South Rossie, AS 22326"}
{"Paisley Miller"} | {"588 Lorin Vista +
| Merlinville, NY 79007"}
Whats up with the {" on each line.
Help
On 06/09/2014 10:02 AM, Bruce wrote:
What's up with the '[' deref. in the execute?I have a table:create table truck (name varchar(45),address varchar(150));doing an insert:for i in range (0,10):meme = fake.name()address = fake.address()print (meme,address)cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", ([meme], [address]))conn.commit()Heres what the data looks like:xcv=# select * from truck2;name | address-----------------------+------------------------------------{"Hana Mosciski"} | {"9597 Rosalia Rue +| South Rossie, AS 22326"}{"Paisley Miller"} | {"588 Lorin Vista +| Merlinville, NY 79007"}Whats up with the {" on each line.Help
That's probably it. Let me see if I can do the insert another way.
---------- Forwarded message ----------
From: Rob Sargent <robjsargent@gmail.com>
Date: Mon, Jun 9, 2014 at 12:02 PM
Subject: Re: [SQL] Problem with strange chars in text filed.
To: Bruce <okbishop@gmail.com>
From: Rob Sargent <robjsargent@gmail.com>
Date: Mon, Jun 9, 2014 at 12:02 PM
Subject: Re: [SQL] Problem with strange chars in text filed.
To: Bruce <okbishop@gmail.com>
Well {" is the array printing syntax for pg.
What language are you using? If it's python, it looks like you're making a list/array with "[meme]"
Note. I top-posted here because this is off list. Best to stick with the list so everyone is up-to-date, and there top-posting is frowned upon (seriously so)
On 06/09/2014 10:57 AM, Bruce wrote:
What language are you using? If it's python, it looks like you're making a list/array with "[meme]"
Note. I top-posted here because this is off list. Best to stick with the list so everyone is up-to-date, and there top-posting is frowned upon (seriously so)
On 06/09/2014 10:57 AM, Bruce wrote:
That was in the example I had. Do you think it's what's causing the {" in the table?On Mon, Jun 9, 2014 at 11:07 AM, Rob Sargent <robjsargent@gmail.com> wrote:What's up with the '[' deref. in the execute?On 06/09/2014 10:02 AM, Bruce wrote:I have a table:create table truck (name varchar(45),address varchar(150));doing an insert:for i in range (0,10):meme = fake.name()address = fake.address()print (meme,address)cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", ([meme], [address]))conn.commit()Heres what the data looks like:xcv=# select * from truck2;name | address-----------------------+------------------------------------{"Hana Mosciski"} | {"9597 Rosalia Rue +| South Rossie, AS 22326"}{"Paisley Miller"} | {"588 Lorin Vista +| Merlinville, NY 79007"}Whats up with the {" on each line.Help
On 06/09/2014 09:02 AM, Bruce wrote: > I have a table: > create table truck (name varchar(45),address varchar(150)); > > doing an insert: > for i in range (0,10): > meme = fake.name <http://fake.name>() > address = fake.address() > print (meme,address) > cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", ([meme], [address])) > conn.commit() Assuming you are using psycopg2 the answer is here: http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries so: cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", (meme, address)) or cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", [meme, address]) > > Help > -- Adrian Klaver adrian.klaver@aklaver.com
Thanks very much for the help. I am most great full.
Regards
On Mon, Jun 9, 2014 at 6:06 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 06/09/2014 09:02 AM, Bruce wrote:I have a table:meme = fake.name <http://fake.name>()
create table truck (name varchar(45),address varchar(150));
doing an insert:
for i in range (0,10):
address = fake.address()
print (meme,address)
cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", ([meme], [address]))
conn.commit()
Assuming you are using psycopg2 the answer is here:
http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries
so:
cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", (meme, address))
or
cur.execute("INSERT INTO TRUCK2 VALUES (%s, %s)", [meme, address])
Help
--
Adrian Klaver
adrian.klaver@aklaver.com