Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf- 8 -*-
- # Python 2.X
- import time
- import psycopg2
- con = psycopg2.connect(
- database="test",
- user="postgres",
- password="",
- host="127.0.0.1",
- port="5432"
- )
- cur = con.cursor()
- cur.execute('''CREATE TABLE IF NOT EXISTS test
- (id SERIAL PRIMARY KEY NOT NULL,
- name TEXT NOT NULL,
- age INT NOT NULL,
- department CHAR(50));''')
- a = time.clock()
- # for i in range(1000000): cur.execute("INSERT INTO test (name,age,department) VALUES ('John', 18, 'ICT')")
- # con.commit()
- ##cur.execute("SELECT name, age, department FROM test WHERE id=300000"); rows = cur.fetchall()
- ##cur.execute("SELECT name, age, department FROM test WHERE id<30"); rows = cur.fetchall()
- cur.execute("SELECT COUNT(*) FROM test WHERE id<100000 GROUP BY age"); rows = cur.fetchall()
- ##cur.execute("show data_directory;"); rows = cur.fetchall()
- print time.clock() - a
- for u in rows: print u[0]
- '''
- 1 mln notes ~= 100-120 mb/ Count
- speed for select for table^1000 notes ~= 3ms
- speed for select for table^1000000 notes ~= 100ms
- '''
- con.close()
- print('ok')
Add Comment
Please, Sign In to add comment