Skip to content
Advertisement

How to parameterize create table function for PostgreSQL in python

I need to dynamically create tables in python this statement works when the variable is statically identified but when I use a variable I get the following error

JavaScript

When I change to using this code it will work

JavaScript

Here is the error

JavaScript

The only thing not in this is a method to manage connection parameters that is working

new error

JavaScript

RecursionError: maximum recursion depth exceeded

Advertisement

Answer

Using sql module from psycopg2 to dynamically build a CREATE TABLE statement safely.

JavaScript

You can then use the built SQL to actually create the table:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement