Reputation: 2224
I.E.
In the following statment
COPY "TableName"
FROM 'MyVARIABLE/filename.csv';
Can I set my variable with something?
Upvotes: 1
Views: 1600
Reputation: 7144
Yes, but only with procedural language not plain sql.
create function copyin( _tablename name, _filename text )
returns void
language plpgsql as $this$
declare sql text;
begin
sql := 'COPY ' || quote_ident(_tablename) || ' FROM ' || quote_literal(_filename);
execute sql;
return;
end;
$this$;
SELECT copyin( 'froobles', '/tmp/froobles.csv' );
Upvotes: 1