32
loading...
This website collects cookies to deliver better user experience
import argparse
import getpass
import psycopg2
import psycopg2.extras
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_schema = %s and table_name = %s;
data_types = db_cursor.fetchall()
column_def = dict((x,y) for x,y in data_types)
execute_values
which allows multiple tuples to be inserted at one time. Here is the SQL.insert_sql = 'INSERT INTO ' + args.schema +"."+ args.tablename + ' (' + ','.join(column_names) + ') VALUES %s'
execute_many
.psycopg2.extras.execute_values(db_cursor,insert_sql,values)