func.sql 505 Bytes
Newer Older
haoyuz3's avatar
haoyuz3 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
create or replace function add_provtuple(
	tablename regclass
)
returns void
as $$
declare
	curid integer := 0;
	tupleid text;
	_ctid tid;
begin
	EXECUTE format('alter table %s add column if not exists provtuple varchar(20)', tablename);
	for _ctid in execute 'select ctid from ' || tablename for update
	loop
haoyuz3's avatar
debug    
haoyuz3 committed
14
		tupleid = 't' || curid;
haoyuz3's avatar
haoyuz3 committed
15
16
17
18
19
20
21
22
23
24
25
		EXECUTE format('update %s
		set provtuple = ''%s''
		where ctid = $1', tablename, tupleid)
		using _ctid;

		curid = curid + 1;
	end loop;
end; $$

language plpgsql;