Cette commande fonctionne de PostgreSQL COPIE:Paramètres Pass pour fonction stockée dans Postgres
copy a from '/tmp/main.csv' WITH (FORMAT csv)
mais je veux que le tablename et filepath à Générée dynamiquement. Comment puis-je faire ceci?
J'ai essayé de suivre en appelant le select import_csv('/tmp/main.csv','a');
CREATE OR REPLACE FUNCTION import_csv(
csv_path text,
target_table text)
RETURNS void AS
$BODY$
begin
set schema 'public';
raise notice 'CSV PATH: %,TABLE NAME: %',csv_path,target_table;
execute format('copy %I from %I WITH (FORMAT csv)',target_table, csv_path);
return;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION import_csv(text, text)
OWNER TO postgres;
Je suis arrivé Erreur:
NOTICE: CSV PATH: /tmp/main.csv,TABLE NAME: a
ERROR: syntax error at or near ""/tmp/main.csv""
LINE 1:
copy a from "/tmp/main.csv" WITH (FORMAT csv)
Got thanks.how à propos de tronquer la table juste avant la ligne d'exécuter le format –
'exécuter le format ('tronquer% I', target_table);' –
Thanks.I ont avez encore modifié la question –