I have this code
create or replace function foo(text)returns int as $$ begin
copy (select * from (delete from bar a where a.id not in(select b.id from bar b where a.id=b.id limit 32 offset 0) returning *) as g) to '/home/foo/.bar.data';
return 1;
end $$ language plpgsql cost 50;
but it cannot create the function and gives the following error
ERROR: syntax error at or near "from"
LINE 4: copy(select * from(delete from bar a ...
^
********** Error **********
ERROR: syntax error at or near "from"
SQL state: 42601
Character: 29
The delete command (delete from bar ...)
is prepared and run without any problem when I call it alone.
I also tried this(without select), same error.
copy (delete from bar a where a.id not in(select b.id from bar b where a.id=b.id limit 32 offset 0) returning *) to '/home/foo/.bar.data';
All I want is delete from the table and copy to a file.
Also how may I have void method in pgsql?