
drop table if exists fastcopy1;
create table fastcopy1 as select generate_series(1,100000)::integer, repeat('a', 1500)::text;

copy fastcopy1
to '/tmp/fastcopy1' binary;

drop table fastcopy1;

drop table if exists fastcopy2;
create table fastcopy2 as select generate_series(1,100000)::integer;

copy fastcopy2
to '/tmp/fastcopy2' binary;

drop table fastcopy2;

-- table to test whether particular commands write WAL or not
-- relies on the fact that temp table writes do not write WAL

drop table if exists xlogpos;
create temp table xlogpos (id integer primary key, pos text);
insert into xlogpos values (1, pg_current_xlog_insert_location());

create or replace function wasWALwritten (expectation boolean) returns text 
as $$
declare
	WALresult boolean;
begin

select (case when position(pg_current_xlog_insert_location() in pos) = 1
            then false
			else true
	   end) into WALresult
from xlogpos where id = 1;

if (WALresult and expectation) or (not WALresult and not expectation) then
	return true;
else
	return false;
end if;

end;
$$ language plpgsql;

update xlogpos set pos = pg_current_xlog_insert_location() where id = 1;
--returns false because our expectation that no WAL has been written should be true
select wasWALwritten(true);

update xlogpos set pos = pg_current_xlog_insert_location() where id = 1;
--returns true because our expectation that no WAL has been written should be true
select wasWALwritten(false);
