Skip to content
Advertisement

Tag: python

How to automate parameters passed into pandas.read_sql?

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

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:

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

Advertisement