I'm trying to load data that is the result of a Python 2.7 library - pg8000 query against a AWS Redshift table.
First I query a Redshift table for results and it provides them inside a tuple containing values in a list.
Example:
value_tuple = ([datetime.date(2016, 10, 2), 1, 1, 123123], [datetime.date(2016, 10, 2), 1, 2, 3131312])
I'd like to insert these values into another table but am running into a few problems creating the insert statement. I'm open to inserting all the values individually, but I'd rather do them all at once.
The table I'm working with looks like this:
| date_column | value_1 | value_2 | value_count |
| 2016-10-01 | 1 | 2 | 300 |
First I tried to create an update query that used just a single list inside the tuple
update_query = """insert into my_schema.my_table_to_update
values %s
""" % str(value_tuple[0])
This way the update_query becomes:
'insert into my_schema.my_table_to_update\n values [datetime.date(2016, 10, 2), 1, 1, 123123]\n '
When I run the update query against the table I get this error:
pg8000.core.ProgrammingError: (u'ERROR', u'42601', u'syntax error at or near "["', u'70', u'/home/rdsdb/padb/src/pg/src/backend/parser/parser_scan.l', u'699', u'yyerror', u'', u'')
I think this means I can't use the list format of the results to insert into the table.
What is a functional, and preferably efficient, way of inserting this data into Redshift?