Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sindhu Madhadi
csed516-2021au
Commits
cd695774
Commit
cd695774
authored
Dec 04, 2021
by
Sindhu Madhadi
Browse files
Upload New File
parent
f4526af6
Changes
1
Hide whitespace changes
Inline
Side-by-side
hw/hw4/starter-code/mini2-vertica/sample1.py
0 → 100644
View file @
cd695774
import
vertica_python
as
vp
args
=
{
'host'
:
'127.0.0.1'
,
'port'
:
5433
,
'user'
:
'dbadmin'
,
'password'
:
''
,
'database'
:
'docker'
,
# 10 minutes timeout on queries
'read_timeout'
:
600
,
# default throw error on invalid UTF-8 results
'unicode_error'
:
'strict'
,
# SSL is disabled by default
'ssl'
:
False
,
# connection timeout is not enabled by default
'connection_timeout'
:
5
}
conn
=
vp
.
connect
(
**
args
)
cur
=
conn
.
cursor
()
cur
.
execute
(
"""
CREATE SCHEMA lobsters;
CREATE TABLE lobsters.tags ( id integer NOT NULL, tag varchar(64));
CREATE TABLE lobsters.taggings (id integer NOT NULL, story_id integer NOT NULL, tag_id integer NOT NULL);
CREATE TABLE lobsters.hiddens (id integer NOT NULL, user_id integer NOT NULL, story_id integer NOT NULL);
CREATE TABLE lobsters.stories (
id integer NOT NULL,
created_at TIMESTAMP,
description varchar(4095),
hotness float,
markeddown_description varchar(4095),
short_id varchar(255),
title varchar(1023),
upvotes integer,
downvotes integer,
url varchar(255),
user_id integer);
"""
)
cur
.
fetchone
()
cur
.
fetchall
()
with
open
(
"taggings.csv"
,
"rb"
)
as
f
:
cur
.
copy
(
"COPY lobsters.taggings from stdin DELIMITER ','"
,
f
)
with
open
(
"hidden.csv"
,
"rb"
)
as
f
:
cur
.
copy
(
"COPY lobsters.hiddens from stdin DELIMITER ','"
,
f
)
with
open
(
"stories.csv"
,
"rb"
)
as
f
:
cur
.
copy
(
"COPY lobsters.stories from stdin DELIMITER ','"
,
f
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment