Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import vertica_python
- connection_info = {
- 'host': '127.0.0.1',
- 'port': 5433,
- 'user': 'dbadmin',
- 'password': '',
- 'database': 'docker',
- 'autocommit': True,
- }
- def create_table():
- with vertica_python.connect(**connection_info) as connection:
- cursor = connection.cursor()
- cursor.execute("""
- CREATE TABLE views (
- id IDENTITY,
- user_id INTEGER NOT NULL,
- movie_id VARCHAR(256) NOT NULL,
- viewed_frame INTEGER NOT NULL
- );
- """)
- def insert_into_table():
- with vertica_python.connect(**connection_info) as connection:
- cursor = connection.cursor()
- cursor.execute("""
- INSERT INTO views (user_id, movie_id, viewed_frame) VALUES (
- 500271,
- 'tt0120338',
- 1611902873
- );
- """)
- def read_from_table():
- with vertica_python.connect(**connection_info) as connection:
- cursor = connection.cursor()
- cursor.execute("""
- SELECT * FROM views;
- """)
- for row in cursor.iterate():
- print(row)
- create_table()
- insert_into_table()
- read_from_table()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement