There are similar questions but they didn't address my problem: I have a stored procedure defined in my remote database. As part of it operation, the SP has to bulk insert from a local file (through my application running on my local machine): the procedure:
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;
the path supplied to the SP is on local machine:
select * from upsert_realtime('/home/.../travel_time.txt','realtime_travel_time');
Therefore I get this error:
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
The only thing that comes into my mind is to somehow automatically scp
the file to the postgresql server and then run the SP, which is not the best idea.
can you help me find a solution? thanks
thanks