Q: Dynamic "CREATE TABLE" statement in psycopg2 / python I currently develop a csv uploader to a postgres-database with python and psycopg2. Per file it should create an own table with the headers of the csv-file as attributes. Does anyone could help me with the CREATE TABLE statement?
Up to now I read the first line of the csv-file and then I want to create the table. But how do I specify the various number of attributes? I do not want to do string concatenation because of sql injections... I know about the option of using %s but I need from file to file a different amount of attributes.
For example:
For a csv file with the header 'id,name,address' it should generate the following statement:
CREATE TABLE test(id SERIAL PRIMARY KEY, name VARCHAR(64), address VARCHAR(64))

For a csv file with the header 'id,age,location,car_type' it should generate the following statemtn:
CREATE TABLE test(id SERIAL PRIMARY KEY, age INTEGER, location VARCHAR(64), car_type VARCHAR(64))

Both statements should be generated by the same python-code.
Does anybody has an idea?
Thank you!
