I am trying to create a methodology for passing parameters automatically through something like locals(), similarly to how f-strings work. How it currently works However, this approach means I cannot copy-paste the SQL into SQL developer or similar, and run it from there. So I would like an approach that makes use of parameters instead. There seems to be two
Tag: python
psycopg2 sql.SQL: Composed elements must be Composable
import psycopg2 from psycopg2 import sql import datetime def connect(conn): “”” Connect to the PostgreSQL database server “”” # create a cursor cur = conn….
psycopg2 takes a value as a column
I’m trying to create a table using psycopg2 and then insert outer data from some jsons. For this reason I defined 2 function: create_words_table() and insert_data(): So, attempting to execute them: I got further error: Looking at documentation, I don’t see any mistake applying simple INSERT query and can’t understand why psycopg2 takes a tuple after word VALUE as a
Pyodbc and AWS Lambda
I have a fairly simple SQL query that’s taking forever to run in my Lambda function and I don’t know why. I know OR statements can be a killer in SQL, but in my database editor, it runs in about 800ms. Why would it take longer in a Lambda function? I’m using cursor.execute() and passing the SQL statement. SQL Query:
Mysql / Maridb Python Connector is not loading data into table
The code checks if there is a table with the same name in the db and then potentially drops it, creates a new table and loads the data of the csv file into the table. When executing the code it seems like everything is working but when going in the mariadb command prompt the created table is empty even though
Only show rows in a table if something changed in previous row
I have a table with a lot of records (6+ million) but most of the rows per ID are all the same. Example: Row Date ID Col1 Col2 Col3 Col4 Col5 1 01-01-2021 1 a b c d e 2 02-01-2021 1 a b c d x 3 03-…
String table name not working in a query with psycopg2
I would like to generate dynamic queries with variables for column names and table name. This is my code: query = sql.SQL(“select {fields} from {table}”).format(fields=sql.SQL(‘,’).join([ …
PYTHON – Dynamically update multiple columns using a custom MariaDB connector
While reading this question: SQL Multiple Updates vs single Update performance I was wondering how could I dynamically implement an update for several variables at the same time using a connector like MariaDB’s. Reading the official documentation I did not find anything similar. This question is similar, and it has helped me to understand how to use parametrized queries with
Compare two SQL tables and return count of rows with changes
I have two partitions from an SQL table containing num_key records. I need to compare and count changes in the February records versus the January records. SAMPLE DATA AND DESIRED RESULTS: ptn_dt = ‘2019-01-31’ (January) num_key active_indicator 111 true 112 false 113 false 114 false 115 true 116 true ptn_dt = ‘2019-02-28’ (February) num_key active_indicator 111 true 112 false 113
Insert into with Cursor.executemany and a Python list
Can someone please explain to me what is wrong with this code? I get the “parameters are of unsupported type” error. Is it not possible to feed a list into cursor.executemany? The type of the column is float not null. Answer The values for cursor.executemany must be a sequence of tuples: This is a logical extension of cursor.execute requiring a