Python
에서 여러 번 루프로 자체 작성 postgresql
함수를 실행하고 있습니다. 이렇게하려면 psycopg2
프레임 워크를 사용하고 있습니다. 내가 오류가 나는 python
스크립트가 실행할 때함수 실행 후 임시 테이블 삭제
CREATE OR REPLACE FUNCTION my_func()
RETURNS void AS
$$
BEGIN
-- create a temporary table that should be deleted after
-- the functions finishes
-- normally a CREATE TABLE ... would be here
CREATE TEMPORARY TABLE temp_t
(
seq integer,
...
) ON COMMIT DROP;
-- now the insert
INSERT INTO temp_t
SELECT
...
END
$$
LANGUAGE 'plpgsql';
그게 기본적으로 파이썬 부분
import time
import psycopg2
conn = psycopg2.connect(host="localhost", user="user", password="...", dbname="some_db")
cur = conn.cursor()
for i in range(1, 11):
print i
print time.clock()
cur.callproc("my_func")
print time.clock()
cur.close()
conn.close()
: 기능은 나는 다음과 같은 구조 께서 쓴 기본적으로
---> relation "temp_t" already exists
I 함수를 실행하는 데 걸리는 시간을 측정하려고합니다. 그러면 루프가 여러 번 실행됩니다. SELECT
의 결과를 임시 테이블에 저장하면 일반적으로 출력 테이블을 생성하는 부분을 대체해야합니다. Python
에서 기능을 실행 한 후 postgres
이 기능을 삭제하지 않는 이유는 무엇입니까?