2015-01-28 5 views
0

비슷한 질문이 있지만 내 문제를 해결하지 못했습니다. 원격 데이터베이스에 저장 프로 시저가 정의되어 있습니다. 그 동작의 일부로서, SP는 (내 로컬 컴퓨터상에서 실행 내 적용을 통해)는 로컬 파일로부터의 대량 삽입을 가지고 의 절차 :로컬 파일의 원격 데이터베이스에 복사

CREATE OR REPLACE FUNCTION upsert_realtime(path text, traveltime_table regclass) 
    RETURNS void AS 
$BODY$ 
BEGIN 
    EXECUTE format('COPY temp_table(link_id,start_time,end_time,travel_time,interval_time, travel_mode) FROM %L DELIMITER '';'' CSV', path); 
    --...  
END; 
$BODY$ 
    LANGUAGE plpgsql VOLATILE 
    COST 100; 
ALTER FUNCTION upsert_realtime(text, regclass) 
    OWNER TO postgres; 

SP로 공급되는 경로가 로컬 머신이다

terminate called after throwing an instance of 'soci::postgresql_soci_error' 
    what(): Cannot execute query. ERROR: could not open file "/home/.../travel_time.txt" for reading: No such file or directory 

내 마음에 오는 유일한 방법을 t 파일 어떻게 든 자동으로 scp을하는 것입니다

select * from upsert_realtime('/home/.../travel_time.txt','realtime_travel_time'); 

그러므로 나는이 오류 그는 postgresql 서버를 실행 한 다음 SP를 실행하는 것이 가장 좋은 생각은 아닙니다. 해결책을 찾도록 도와 줄 수 있습니까? 감사합니다 감사합니다

답변

1

당신은 using the wrong path입니다. 이것은 일반적인 오류의 원인입니다. 그것은 "서버의 관점에서"에 관한 것입니다. 당신이 사용할 수있는 경로가없는 경우

COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible by the PostgreSQL user (the user ID the server runs as) and the name must be specified from the viewpoint of the server. When PROGRAM is specified, the server executes the given command and reads from the standard output of the program, or writes to the standard input of the program. The command must be specified from the viewpoint of the server, and be executable by the PostgreSQL user. When STDIN or STDOUT is specified, data is transmitted via the connection between the client and the server.

, 당신은

  • 이 서버에 프로그램을 호출

    • 이동하여 서버에 파일이 필요하고, 올바른 경로를 사용하는 수 로컬 서버에 액세스하려면
    • psql을 사용하여 원격 서버에 연결하고 로컬 파일을 읽습니다.
  • 관련 문제