我正在尝试在变量中存储路径,以便在Copy语句中使用它,但是 它不起作用。
DO $$
DECLARE PATH char(100):='/home/gabriela/Documents/q_types.csv';
BEGIN
CREATE TABLE mydbschema.example(
ID integer NOT NULL PRIMARY KEY,
Value char(15) NOT NULL
);
COPY mydbschema.example FROM 'PATH' DELIMITER ',';
END $$;
答案 0 :(得分:0)
create or replace function load(file_name text)
returns void as $$
Declare
csv_path text:= '/home/gabriela/Documents/';
t_path text:=csv_path||file_name;
begin
-- copy the data from csv file
execute format('copy example from %L with delimiter '','' quote ''}'' csv', t_path);
end;
$$ language plpgsql;
DO $$ BEGIN
PERFORM load('example.csv');
END $$;