136 questions
0
votes
0
answers
245
views
Use Jinja template for table name inside SQLExecuteQueryOperator params or parameter
I am using SQLExecuteQuery Operator to query a table, which name is dynamically generated (e.g. staging_{{ts_nodash}}).
I know I can, but I don't want to use the jinja template inside sql (example ...
2
votes
1
answer
71
views
Connection and cursor still usable outside with block
My system:
Windows 10 x64
Python version 3.9.4
SQLite3 module integrated in the standard library
A DB connection and a cursor are both considered resources, so that I can use a with clause.
I know ...
-1
votes
1
answer
1k
views
Can't catch connection error clickhouse-driver db api
I'm trying to catch a connection error when connecting to kx using the clickhouse-driver db api in python. But for some reason, the try: block passes without errors, and I don't get exception
def ...
0
votes
1
answer
1k
views
How to catch exception clickhouse_driver dbapi?
I want to catch exception while executing scipts/connecting to base using clickhouse_driver-drive dbapi.
Can I catch errors codes and errors message like
errorcodes.lookup(e.pgcode)
and
e.diag....
3
votes
0
answers
53
views
Python's sqlite3 module: get query with escaped parameters [duplicate]
The sqlite3 module allows one to use parameter substitution for queries like so:
import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table lang (name,...
0
votes
1
answer
533
views
How to preform insert into BigQuery table of list of values using dbapi
I have a question regarding performing insert into a table in BigQuery using the DBAPI .
The simple insert of 1 value I was able to preform , my question is how to preform insert of list of values.
I ...
0
votes
1
answer
1k
views
Why do sqlite3 DB_API qmark and named style not work in "select where" queries?
Assuming I have a database with table users with a row:
ID = 0, name = 'myName'
I can get the ID value (assuming I'm connected) by using either:
cursor.execute("""SELECT ID FROM users ...
1
vote
4
answers
8k
views
IBM Db2 : An unexpected token "as" was found following "SELECT test_score " (SQL0104N)
I am now having trouble with IBM Db2 using queries. I have a code below:
test_score_distribution = %sql SELECT test_score as "Test Score", count(*) as "Frequency" from ...
0
votes
1
answer
544
views
doubts about DB-API e SQLAlchemy
link da questão
Briefly, I want to know what this "DB-API" mechanism is.
Are there multiple DB-APIs (there are more than 1 DB-API)?
Is it just a 'rules' document?
have a source code?
What ...
2
votes
0
answers
310
views
What is actual SQL produced by cursor.execute() through python dbapi 2.0?
I'll admit it. I've been doing this for literally decades:
sql = 'select * from whatever where key = "%s"' % ('thing')
cursor.execute(sql)
One big reason is that
print(sql)
tells me ...
1
vote
1
answer
2k
views
Is there a way to select schema in python hdbcli dbapi?
According to documentation, parameters needed to connect to HANA database are host, port, user and password.
from hdbcli import dbapi
conn = dbapi.connect(
address="<hostname>",
...
3
votes
1
answer
81
views
PyGreSQL is returning unexpected result for a one column select statement
I have the following PostgreSQL database table:
TABLE session_monitor
(
id int,
customer_name varchar(150)
)
When I am running the following code:
seq = pg_cur.execute("SELECT id ,...
0
votes
1
answer
262
views
Why does this rollback function not work as expected
I am going to execute 2 sql queries and I want to put them in a transaction, if any query failed then call rollback(). The code is shown as following and 2 queries are
str_trunction: truncate the ...
1
vote
1
answer
2k
views
snowflake python connector - Time to make database connection
Python code is taking around 2-3 secs to make the snowflake database connection. Is it expected behaviour ? OR are there any parameters which will speed up connection time.
Here is the sample code:
...
0
votes
0
answers
405
views
share db connection pool across python processes
I have build an application (python3.6) which keeps checking a directory for incoming files and when there are files it spawns some python processes in order to work on those files.This work involves ...
1
vote
1
answer
2k
views
Eager Inner Join in SQLAlchemy
I must be a moron, because I cannot figure out how to ask SQLAlchemy to perform a simple, non-lazy inner join. In other words, return all the results in a single query.
The raw SQL query I would like ...
2
votes
2
answers
8k
views
SAP HANA Python Connection HDBCLI
After successfully installing the HDBCLI driver and connecting SAP HANA with Python, I created the below code to test the connection, however, I got an error:
Error: (-10719, "Connect failed (invalid ...
10
votes
2
answers
7k
views
Identifying sqlalchemy.exc.OperationalError
I'm trying to catch mysql/sqlalchemy OperationalErrors and replace handle access denied (1045) differently from connection refused (2003)
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError)...
0
votes
1
answer
1k
views
syntax error when using substring in a join expression with PostgreSQL
I'm working with postgresql using the Python DB API.
The substring expression I'm using works fine when on its own, but when I put it in the context of a join command I get a syntax error, and I can'...
-2
votes
2
answers
3k
views
Python SQLite query returns None
The following SQLite query returns 3:
SELECT MAX(depth) FROM mpitree WHERE child = 2
But this code evaluates to None:
def ancestors_depth(self):
self.cursor.execute("SELECT MAX(depth) FROM ...
0
votes
0
answers
267
views
Python DBAPI cursor fetchmany in a generator is closed too early
import dbapi2
conn = dbapi2.connect("db", autocommit=True)
def fetch_generator():
cursor = conn.cursor()
for res in cursor.execute('select * from table'):
yield res
def generator_1():...
3
votes
1
answer
5k
views
Remote Oracle DB connection in python
I want to connect to remote oracle db using python.
Tried to using cx_Oracle.
Here is my code:
import cx_Oracle
adr = 'server_addres'
uid = 'user_id'
pwd = 'pwd'
port = 'port'
cx_Oracle.connect(...
3
votes
1
answer
1k
views
Is having a global database connection allowed in WSGI applications?
I need to create a simple project in Flask. I don't want to use SQLAlchemy. In the code snippet below, everyone that connects to the server uses the same connection object but for each request, a new ...
0
votes
1
answer
842
views
INSERT INTO using Postgres on PYTHON DB-API
I'm trying to learn to add backend to a simple web app using postgreSQL and Python DB-API.
When running the app, why do I get an error if the function get_posts() in forumdb. python uses c. execute ("...
0
votes
1
answer
74
views
Correct use of keys when joining tables in SQL
Currently learning data science with SQLite and Pandas. Working on a political contributions dataset. I'm wondering what is the purpose of WHERE contributors.candidate_id = candidates.id in the code ...