Пример #1
0
 def load(self):
     with self.conn.cursor() as cursor:
         headers = self.headers.keys()
         stmt = SQL("COPY {} ({}) FROM STDIN WITH CSV HEADER NULL AS ''")
         columns = Composed([Identifier(c) for c in headers])
         columns = columns.join(', ')
         stmt = stmt.format(Identifier(self.table), columns)
         # print stmt.as_string(cursor)
         cursor.copy_expert(stmt, self.proxy)
     self.conn.commit()
Пример #2
0
 def load(self, fh, delimiter):
     with self.conn.cursor() as cursor:
         headers = list(self.headers.keys())
         stmt = SQL("COPY {} ({}) FROM STDIN "
                    "WITH CSV HEADER DELIMITER AS {} NULL AS ''")
         columns = Composed([Identifier(c) for c in headers])
         columns = columns.join(', ')
         stmt = stmt.format(Identifier(self.table), columns,
                            Literal(delimiter))
         print(stmt.as_string(cursor))
         cursor.copy_expert(stmt, fh)
     self.conn.commit()