FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-driver/samples/LoadCSVFile.py at master · Teradata/python-driver · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Teradata
/
python-driver
Public
Notifications
You must be signed in to change notification settings
Fork
29
Star
74
Code
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python-driver
/
samples
/
LoadCSVFile.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (19 loc) · 1.32 KB
Breadcrumbs
python-driver
/
samples
/
LoadCSVFile.py
Copy path
File metadata and controls
25 lines (19 loc) · 1.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright 2023 by Teradata Corporation. All rights reserved.
# This sample program demonstrates two different approaches to load data values
# from a CSV file and 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
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"
)
print
(
"Slower approach - use the Python csv module to parse data values from a CSV file"
)
with
open
(
"airports.csv"
,
newline
=
""
)
as
f
:
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
() ]
cur
.
execute
(
"delete from Airports"
)
print
(
"Faster approach - the driver loads data values from a CSV file"
)
cur
.
execute
(
"{fn teradata_read_csv(airports.csv)}insert into Airports (?, ?, ?)"
)
cur
.
execute
(
"select AirportCode, Airport, City from Airports order by AirportCode"
)
[
print
(
row
)
for
row
in
cur
.
fetchall
() ]
Back
|
FazBrowse Home
|
New Git URL