Skip to content
Advertisement

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 answer that works with no string concatenation Thanks to Adrian for the help Answer sql.Identifier is for SQL

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’s timezone, it returns with a problem select

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 a column “name” of type VARCHAR. However, when I attempt

Advertisement