Advertisement
alex0sunny

vertica-test

Dec 2nd, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. import vertica_python
  2.  
  3.  
  4. connection_info = {
  5.     'host': '127.0.0.1',
  6.     'port': 5433,
  7.     'user': 'dbadmin',
  8.     'password': '',
  9.     'database': 'docker',
  10.     'autocommit': True,
  11. }
  12.  
  13.  
  14. def create_table():
  15.     with vertica_python.connect(**connection_info) as connection:
  16.         cursor = connection.cursor()
  17.         cursor.execute("""
  18.        CREATE TABLE views (
  19.            id IDENTITY,
  20.            user_id INTEGER NOT NULL,
  21.            movie_id VARCHAR(256) NOT NULL,
  22.            viewed_frame INTEGER NOT NULL
  23.        );
  24.        """)
  25.  
  26.  
  27. def insert_into_table():
  28.     with vertica_python.connect(**connection_info) as connection:
  29.         cursor = connection.cursor()
  30.         cursor.execute("""
  31.        INSERT INTO views (user_id, movie_id, viewed_frame) VALUES (
  32.            500271,
  33.            'tt0120338',
  34.            1611902873
  35.        );        
  36.        """)
  37.  
  38.  
  39. def read_from_table():
  40.     with vertica_python.connect(**connection_info) as connection:
  41.         cursor = connection.cursor()
  42.         cursor.execute("""
  43.            SELECT * FROM views;
  44.        """)
  45.         for row in cursor.iterate():
  46.             print(row)
  47.  
  48.  
  49. create_table()
  50. insert_into_table()
  51. read_from_table()
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement