JSON translated into SQL by python

Peter Otten __peter__ at web.de
Sat Nov 23 09:52:02 CET 2013

Aaron G. wrote:

> I am new to programming python for JSON to SQL and I was wondering why
> this does not work. All the values for entering the DB are correct. The
> EnterpriseValue data is not entering the database.

> #collect data from JSON source at Yahoo
> url = ["db", "http://y.ahoo.it/wlB89"]
> #check all sites
> checkstatus(url[]);
> #retrieve EnterpriseValue data from yahoo to DB
> url = "http://y.ahoo.it/wlB89"
> data = helper.openJSON_URL(url)
> #store data
> curObservation = data["EnterpriseValue"]
> #connect to amazon and post data from Yahoo
> conn = inti_psql_amazon("db name", "db user", "password", "db source")

inti_psql_amazon? Please post your actual code. Cut and paste, don't retype. 
If there's an exception, post that, too. The source code of


might be interesting, too. A commit() on the db cursor might do wonders.

Enterprise_Value float, PRIMARY KEY(ID));"
> query = "INSERT INTO TABLE temp2 (enterprise) VALUES("+ 
str(curObservation) +");"

As a general remark, don't build your queries like that, rely on the API to 
insert the values. E. g.:

cursor = conn.cursor()
cursor.execute("insert into table temp2 (enterprise) values (?);", 

(Some databases use '%s' instead of '?')

> do_query_amazon(conn, query)
> close_psql_amazon(conn)

More information about the Python-list mailing list