Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
417 views

Python 3.5.2, stdlib sqlite3. I'm trying to issue a SQL query with a dynamic criterion in an IN operator in the WHERE clause: bad code (doesn't work) def top_item_counts_in_installations(cursor, ...
tzot's user avatar
  • 96.6k
0 votes
0 answers
478 views

I am using Python library pymssql to connect to a database. I have never used it before so the error might look trivial. from os import getenv import pymssql server = getenv("192.xxx.xxx.xx") user ...
John Constantine's user avatar
7 votes
2 answers
517 views

Overview Context I am writing unit tests for some higher-order logic that depends on writing to an SQLite3 database. For this I am using twisted.trial.unittest and twisted.enterprise.adbapi....
Louis Thibault's user avatar
2 votes
2 answers
508 views

I have code similar to the following: var1 = 1 var2 = 2 cursor.execute("INSERT INTO mytable VALUES (:var1, :var2)", {'var1': var1, 'var2': var2}) Is there any reason I should use the dictionary ...
jl6's user avatar
  • 6,532
10 votes
2 answers
4k views

Is there any benefit to closing a cursor when using Python's sqlite3 module? Or is it just an artifact of the DB API v2.0 that might only do something useful for other databases? It makes sense that ...
Raymond Hettinger's user avatar
0 votes
1 answer
396 views

Is there a Database API specification for Java that is similar to what exists for Python (PEP249). I'd like to make an application that can be used to connect to databases, universally, without ...
Sailesh Sriram's user avatar
0 votes
1 answer
70 views

I have been searching through Stack Overflow as well as some other online research looking for the correct syntax to insert variables into my SQLite query. However, none of the 3 supported syntaxes ...
user avatar
1 vote
2 answers
2k views

I'm trying to execute this update query from columns in a pandas dataframe: sql = "UPDATE tblhis_ventas SET portabilidad = '%s' WHERE (contrato = '%s' and estado = '%s') " % ( df['portabilidad'], ...
ccalobeto's user avatar
3 votes
2 answers
1k views

I'm trying to update some database fields using a python function to an SQLite DB. I keep getting the following error: ValueError: operation parameter must be str Below is my code. I would love to ...
Evans Wanjau's user avatar
18 votes
1 answer
13k views

I'm trying to understand what this code is doing behind the scenes: import psycopg2 c = psycopg2.connect('db=some_db user=me').cursor() c.execute('select * from some_table') for row in c: pass ...
bertday's user avatar
  • 11k
2 votes
1 answer
1k views

Context: A python 3.6 script is updating a Sqlite database several times a day using sqlite3 module. The database is ~500Mo, each update adds up ~250Ko. Issue: I deliver every updated ...
gleeen.gould's user avatar
0 votes
1 answer
155 views

I have a function which updates a single row in db. def update_one_row(conn, condition, value): with conn.cursor() as curr: curr.execute("""UPDATE persons p SET ...
redacted's user avatar
  • 4,009
4 votes
1 answer
3k views

According to flask docs, we should close the database connection when app context tears down: def get_db(): """Opens a new database connection if there is none yet for the current application ...
max's user avatar
  • 52.8k
5 votes
1 answer
20k views

I have a database schema that might be implemented in a variety of different database engines (let's say an MS Access database that I'll connect to with pyodbc or a SQLite database that I'll connect ...
Drew Hall's user avatar
  • 29.2k
12 votes
3 answers
4k views

What is the correct way to insert the values of numpy integer objects into databases in python 3? In python 2.7 numpy numeric datatypes insert cleanly into sqlite, but they don't in python 3 import ...
David Nehme's user avatar
  • 21.7k
4 votes
1 answer
6k views

It is possible to do async i/o with psycopg2 (which can be read here) however I'm not sure how to do async transactions. Consider this sequence of things: Green Thread 1 starts transaction T GT1 ...
freakish's user avatar
  • 57k
2 votes
1 answer
361 views

I'm using the Snowflake Connector for Python (which implements support for the Python Database API v2 specification) in a script which pulls a number of records from one table, iterates over the ...
Andrew Kirk's user avatar
  • 1,869
0 votes
2 answers
4k views

How do I set transaction level READ UNCOMMITED for all queries done through a SQL Alchemy engine object? I set the isolation_level argument as notated here: http://docs.sqlalchemy.org/en/latest/core/...
michael g's user avatar
  • 103
4 votes
1 answer
2k views

What is the correct method to have the tuple (names) be available via %s in the SQL statement? names = ('David', 'Isaac') sql = 'SELECT * from names WHERE name IN %s' cur.execute(sql,(names,)) The ...
Tsachi's user avatar
  • 57
5 votes
2 answers
207 views

I am working on an online project by Udacity. I am using vagrant configured by them, to run the server containing the Database. Unfortunately when I tried to give the code persistence, the server ...
Abhishek Ghosh's user avatar
0 votes
0 answers
129 views

I'm using SQLAlchemy from within Django, and I can access the thread-local database connection object in Django: from django.db import connection Given that connection object, can I use it to ...
maxm's user avatar
  • 5,431
3 votes
1 answer
770 views

Well, I tried to understand Open Database Connectivity and Python DB-API, but I can't. ODBC is some kind of standard and Python DB-API is another standard, but why not use just one standard? Or maybe ...
user avatar
2 votes
2 answers
4k views

According to the Python DB API, one of the fields in cursor.description returns a type_code; however these are always numbers. How do I convert from type_code (eg. 1) to a data type (eg. TEXT)?
jastr's user avatar
  • 888
6 votes
1 answer
5k views

How can I check for open transactions on a psycopg2 connection? I intend to add it to my unit/functional tests since Python's DB API uses implicit transactions.
Eugene Yarmash's user avatar
1 vote
1 answer
344 views

stmt = "SELECT filecontent FROM filecontent WHERE filecontent_id = %d AND filecontent LIKE '%% %s %%'"%(int(result_file_pri[0]),str(myjson['recordType'])) curs.execute(stmt) Trying to conevert above ...
Pravin's user avatar
  • 707
1 vote
2 answers
497 views

According to psycopg2 documentation we should set autocommit to get the default PostgreSQL behaviour. This even seems to be the preferred approach according to some people. My question is, if this is ...
dvieira's user avatar
  • 693
2 votes
1 answer
562 views

Query results from some Postgres data types are converted to native types by psycopg2. Neither pgdb (PostgreSQL) and cx_Oracle seem to do this. …so my attempt to switch pgdb out for psycopg2cffi is ...
Wilfredo Sánchez Vega's user avatar
0 votes
1 answer
172 views

I have a Python script that uses the pydblite database library. when I run the code once the database is created and records added. if I run the code again an error is generated..Help Code db = ...
Matt A's user avatar
  • 77
2 votes
2 answers
1k views

I am using pg8000 to connect to a PostgreSQL database via Python. I would like to be able to send in dates as parameters via the cursor.execute method: def info_by_month(cursor, year, month): ...
Tim McNamara's user avatar
  • 18.5k
3 votes
1 answer
1k views

I am utilizing PyMySQL with Python 2.7 and try to execute the following statement: 'INSERT INTO %s (%s, %s) VALUES (%s, %s) ON DUPLICATE KEY UPDATE %s = %s' With the following parameters: ('artikel',...
p13n's user avatar
  • 1,004
0 votes
1 answer
376 views

The mysql output: b.query("select * from b where a='" + c + "' limit 1") result = b.store_result() d = result.fetch_row(0) the bottom of WSGI script: start_response('200 OK', [('content-...
user3880134's user avatar
0 votes
0 answers
127 views

there is a value I get from an SQL query which is stored with the name max_dateCS. This variable needs to be input into another SQL query. I am facing a problem doing that as it gives an error ' list ...
user3805624's user avatar
0 votes
1 answer
240 views

I'm writing a utility which I intend to be useable with at least three different database server backends (SQLite3, PostgreSQL, and MySQL). I'm not using an ORM (though I try a fork using SQLAlchemy ...
Jim Dennis's user avatar
  • 17.7k
8 votes
1 answer
8k views

I have a basic program that is supposed to query a database that contains user information. I am trying to select the information for a specific user and print it out to the console. Here is my ...
Sebastian Bartholomew Charles 's user avatar
0 votes
1 answer
14k views

According to psycopg2: insert multiple rows with one query, it is much more efficient to use psycopg2's execute instead of executemany . Can others confirm? The above StackOverflow question suggests ...
ChaimKut's user avatar
  • 2,819
1 vote
1 answer
243 views

I want to use python to execute a CREATE STATEMENT clause, specifying default values for certain columns using parameter substitution with ? (so that I can safely specify defaults from python types). ...
bryhoyt's user avatar
  • 273
3 votes
1 answer
1k views

PEP 249 -- Python Database API Specification v2.0 in the description of .commit() states: Note that if the database supports an auto-commit feature, this must be initially off. An interface method ...
vartec's user avatar
  • 135k
0 votes
1 answer
259 views

I have a Sqlite3 table that has a LastUpdated column containing UTC datetimes formatted as "2013-12-24 07:11:21", and all the rows int that table were updated 2 days ago. I want to write a SELECT ...
Jeff Widman's user avatar
  • 23.8k
1 vote
1 answer
7k views

I am using psycopg2 and how can I delete rows that are older than a certain date? For example: cursor.execute('DELETE FROM datatable WHERE date < %s', datetime.date(2012, 1, 1)) If I write like ...
Robert's user avatar
  • 2,259
1 vote
1 answer
2k views

I want to do exactly what cursor.mogrify does, but in a production appropriate way. I'm updating some legacy Python code that builds queries by concatenating strings. I need to change this to escape ...
Tim Wilder's user avatar
  • 1,647
0 votes
1 answer
157 views

I have worked with Pycassa before and wrote a wrapper to use batch mutation & connection pooling etc. But http://wiki.apache.org/cassandra/ClientOptions recommends now to use CQL 3 based api ...
NullException's user avatar
1 vote
0 answers
380 views

I'm using MySQL Connector/Python 1.0.11 with Python 3.3 and MySQL 5.6.12 to load a csv file into a table via cursor.executemany('INSERT INTO ... VALUES'). With sqlite3 or psycopg2 I can pass a _csv....
Matthew Cornell's user avatar
6 votes
1 answer
4k views

When using database libraries like pyodbc that implement the Python Database API Specification how can you get the fully prepared query after parameter substitution has been applied. I'm making a call ...
Marwan Alsabbagh's user avatar
83 votes
9 answers
228k views

I have a sql statement that returns no hits. For example, 'select * from TAB where 1 = 2'. I want to check how many rows are returned, cursor.execute(query_sql) rs = cursor.fetchall() Here I get ...
Tao Venzke's user avatar
3 votes
0 answers
2k views

I have to dump some data from various databases (Oracle and Postgre, at the moment) into CSV files, while preserving the column type information so the data can be correctly loaded into another ...
Dan Lenski's user avatar
  • 80.5k
55 votes
7 answers
77k views

I'm trying to port some code to Python that uses sqlite databases, and I'm trying to get transactions to work, and I'm getting really confused. I'm really confused by this; I've used sqlite a lot in ...
David Given's user avatar
  • 13.8k
0 votes
1 answer
507 views

If we have a json format data file which stores all of our database data content, such as table name, row, and column, etc content, how can we use DB-API object to insert/update/delete data from json ...
user1342336's user avatar
0 votes
2 answers
1k views

I want to update multiple rows identified by unique key without inserting new rows. Below is my table: CREATE TABLE `insert_update_ignore` ( `obj_id` int(11) NOT NULL, `obj_type` tinyint(4) ...
schemacs's user avatar
  • 2,971
7 votes
2 answers
5k views

How do I get the output from the sql_query? import pyodbc sql_query = "print 'Hello World'" conn = pyodbc.connect("DRIVER={SQL Server}; SERVER=myserver; DATABASE=mydatabase; UID=myusername; PWD=...
ijk's user avatar
  • 175
1 vote
1 answer
76 views

Was hoping to use Django / db-api's built in string excaping, but it looks like it doesn't work for create database commands? from django.db import connections cursor = connections['dbadmin'].cursor()...
hwjp's user avatar
  • 16.2k