I am trying to create a method in python insert records into a table passing in a list of column names, and an associated list of records. I was able to set it up where the column names populated dynamically via a for loop, but I can’t figure out how to do the same thing with values because the psycopg2…
Tag: psycopg2
psycopg2 not escaping quotation from tuple arguments? Using sql.SQL to format arguments
I’m trying to dynamically create a table in postgres with psycopg2. It seems when the arguments are passed, pyscopg2 is not escaping quotations and understanding my query. Code looks like this: The error I’m getting: What print(create_table_str.as_string(conn)) outputs: Edit to show modified answe…
Insertion by removing ‘000000’ in the unix timestamp
I’m inserting some data for python that comes from a GET in API FLASK like JSON, for some reason when python will insert this data or maybe postgres itself, it is removing the 000000 Data json: Insert py: Original date: Date that python is inserting to pgsql: Conversion correct: Even using the website&#…
Create Redshift table with new Geometry type through psycopg2
After Redshift announced support for Geometry types and spatial functions, I’d like to create a table with polygons for all countries. I’m failing to do the INSERT and would appreciate help. Here is …
Create SQL command with a query parameter that checks for NULL but also for other values
I am trying to write a dynamic SQL command using Python / Postgres. In my where clause I want to use a query parameter (which is user defined) that has to look for NULL values within a code column (varchar), but in other cases also for specific numbers. If I have to check for a certain value I use this:
The most efficient method of performing a large number of similar SELECT queries on PostgreSQL?
I have a set of large tables with many records each. I’m writing a Python program that SELECTs a large number of records from these tables, based on the value of multiple columns on those records. Essentially, these are going to be lots of queries of the form: Each table has a different set of columns, …
Creating dynamically-typed tables using psycopg2’s built-in formatting
I’m working on a project in Python that interacts with a PostgreSQL data warehouse, and I’m using the psycopg2 API. I am looking to create dynamically-typed tables. For example: I would like to be able to execute the following code: and end up with a table named “animals” that contains…