-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02a82d7
commit 3b0ce6f
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 全量查询 | ||
# 批量查询 | ||
# 单条查询 | ||
|
||
# 是否需要初始化表格,migration | ||
|
||
import psycopg | ||
|
||
|
||
def get_data(mode=""): | ||
with psycopg.connect( | ||
"dbname=postgres" | ||
+ " " | ||
+ "user=postgres" | ||
+ " " | ||
+ "password=12345678" | ||
+ " " | ||
+ "host=localhost" | ||
+ " " | ||
+ "port=5432" | ||
) as conn: | ||
with conn.cursor() as cur: | ||
# cur.execute( | ||
# """ | ||
# -- Table: public.testtable | ||
# | ||
# -- DROP TABLE IF EXISTS public.testtable; | ||
# | ||
# CREATE TABLE IF NOT EXISTS public.testtable | ||
# ( | ||
# key "integer", | ||
# value "integer" | ||
# ) | ||
# | ||
# TABLESPACE pg_default; | ||
# | ||
# ALTER TABLE IF EXISTS public.testtable | ||
# OWNER to postgres; | ||
# """ | ||
# ) | ||
cur.execute( | ||
"INSERT INTO testtable (key, value) VALUES (" | ||
+ str(i * 100 + j * 2) | ||
+ "," | ||
+ str(j) | ||
+ ")" | ||
) | ||
|
||
cur.execute("SELECT * FROM testtable") | ||
|
||
for record in cur: | ||
print(record) | ||
|
||
conn.commit() |