在COPY FROM语句中使用变量postgresql
我试图在变量中存储路径,在Copy语句中使用它,但是 它不起作用在COPY FROM语句中使用变量postgresql,sql,postgresql,Sql,Postgresql,我试图在变量中存储路径,在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
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 $$;
从路径分隔符“,”复制mydbschema.example;也没用
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 $$;