을 postgres_fdw : (file_fdw 만든) sheetheight와라는 이름의 외국 테이블 : (postgres_fdw 만든) dzlog 외국 테이블 file_fdw에 가입과 PostgreSQL 9.5에서 외국 테이블
내가라는 이름의 외국 테이블이 있습니다. 외국 테이블을 조인에 대한1 나는 다음과 같은 쿼리가 :
SELECT * from dzlog INNER JOIN sheetheight ON dzlog.ullid = sheetheight.ullid
을;
과 EXPLAIN ANALYZE
돌아 다시이 위의 쿼리는 :
-------------------------------------------------
Hash Join (cost=111.66..13688.18 rows=20814 width=2180) (actual time=7670.872.
.8527.844 rows=2499 loops=1)
Hash Cond: (sheetheight.ullid = dzlog.ullid)
-> Foreign Scan on sheetheight (cost=0.00..12968.10 rows=106741 width=150)
(actual time=0.116..570.571 rows=223986 loops=1)
Foreign File: D:\code\sources\sheetHeight_20151025_221244_0000000004987
6878996.csv
Foreign File Size: 18786370
-> Hash (cost=111.17..111.17 rows=39 width=2030) (actual time=7658.661..765
8.661 rows=34107 loops=1)
Buckets: 2048 (originally 1024) Batches: 32 (originally 1) Memory Usa
ge: 4082kB
-> Foreign Scan on dzlog (cost=100.00..111.17 rows=39 width=2030) (ac
tual time=47.162..7578.990 rows=34107 loops=1)
Planning time: 8.755 ms
Execution time: 8530.917 ms
(10 rows)
쿼리의 출력은 두 개의 열이 ullid 명명했다.
ullid, 날짜, 색상 sheetid, dz0, (DZ1), (DZ2), DZ3, dz4, dz5, dz6, dz7, ullid, sheetid 통과 ... 직접적
2- csv 파일 및 SQL 로컬 응용 프로그램에서 파이썬 응용 프로그램에 액세스 할 수 있습니다. Pandas merge dataframe
을 사용하여 파이썬 응용 프로그램에서 csv 파일 및 postgreSQL 로컬 테이블에 직접 액세스하는 대신 FDW를 사용하여 동일한 쿼리를 수행했습니다. 이 원료 조인 조인 그래서 제 CSV 파일을 인출 한 다음 파이썬 팬더 라이브러리를 사용하여 SQL 테이블을 가져, 다음 I 공통 열
import pandas as pd
def rawjoin(query,connection=psycopg2.connect("dbname='mydb' user='qfsa' host='localhost' password='123' port=5433")):
query=("SELECT * FROM dzlog;")
firstTable= pd.read_csv('.\sources\sheetHeight_20151025_221244_000000000498768789.csv', delimiter=';', header=0)
secondTable =pd.read_sql(query,connection)
merged= pd.merge(firstTable, secondTable, on= 'ullid', how='inner')
return merged
결과에 기초하여 두 dataframes을 결합 데이터이다 병합 하나의 열이없는 프레임.
이 차이점에 대해 알고 싶습니다.
q7=("SELECT dzlog.color FROM dzlog,sheetheight WHERE dzlog.ullid = sheetheight.ullid;")
q8=("SELECT sheetheight.defectfound FROM dzlog, sheetheight WHERE dzlog.ullid = sheetheight.ullid;")
q9=("SELECT dzlog.color, sheetheight.defectfound FROM dzlog, sheetheight WHERE dzlog.ullid= sheetheight.ullid;")
그래, 쿼리가 문제였습니다. 귀하의 질문이 올바른 것입니다. – User193452