forked from Teradata/python-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadCSVFile.py
More file actions
16 lines (13 loc) · 925 Bytes
/
LoadCSVFile.py
File metadata and controls
16 lines (13 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Copyright 2018 by Teradata Corporation. All rights reserved.
# This sample program demonstrates how to use the Python csv module to parse data values
# from a CSV file, and then insert those data values into a database table.
# This sample program requires the airports.csv file to be located in the current directory.
import csv
import teradatasql
with open ('airports.csv', newline='') as f:
with teradatasql.connect ('{"host":"whomooz","user":"guest","password":"please"}') as con:
with con.cursor () as cur:
cur.execute ("create volatile table Airports (City varchar(100), Airport varchar(100), AirportCode varchar(10)) on commit preserve rows")
cur.execute ("insert into Airports (?, ?, ?)", [ row for row in csv.reader (f) ])
cur.execute ("select AirportCode, Airport, City from Airports order by AirportCode")
[ print (row) for row in cur.fetchall () ]