postgres之使用python鏈接並操做

取一萬個隨機數,插入數據庫git

import random
import psycopg2
import string

conn=psycopg2.connect(database='postgres',user='postgres',password='postgres',host='192.168.137.3')
cur=conn.cursor()

# print(ran_str,type(ran_str))

for i in range(10000):
    ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 8))  #生成8位的隨機數,包含大小寫字母和數字
    ran_str = ran_str + '@lenovo.com'
    # cur.execute("insert into test8 values(pgp_sym_encrypt('%s','abc','cipher-algo=aes256, compress-algo=0, compress-level=9'))"%(ran_str))
    cur.execute("insert into test10 values(encrypt('%s','aa@ghilkjds*dfjMTR','aes-128'))" %(ran_str))
    conn.commit()

cur.close()
conn.close()
相關文章
相關標籤/搜索