sequencesetvalue(p_last_value integer, p_ev_seqno integer, p_seq_origin bigint, p_seq_id bigint)

8.107. sequencesetvalue(p_last_value integer, p_ev_seqno integer, p_seq_origin bigint, p_seq_id bigint)

Function Properties

Language: PLPGSQL

Return Type: integer

sequenceSetValue (seq_id, seq_origin, ev_seqno, last_value) Set sequence seq_id to have new value last_value.

declare
	v_fqname			text;
begin
	-- ----
	-- Get the sequences fully qualified name
	-- ----
	select slon_quote_brute(PGN.nspname) || '.' ||
			slon_quote_brute(PGC.relname) into v_fqname
		from sl_sequence SQ,
			"pg_catalog".pg_class PGC, "pg_catalog".pg_namespace PGN
		where SQ.seq_id = p_seq_id
			and SQ.seq_reloid = PGC.oid
			and PGC.relnamespace = PGN.oid;
	if not found then
		raise exception 'Slony-I: sequenceSetValue(): sequence % not found', p_seq_id;
	end if;

	-- ----
	-- Update it to the new value
	-- ----
	execute 'select setval(''' || v_fqname ||
			''', ' || p_last_value::text || ')';

	insert into sl_seqlog
			(seql_seqid, seql_origin, seql_ev_seqno, seql_last_value)
			values (p_seq_id, p_seq_origin, p_ev_seqno, p_last_value);

	return p_seq_id;
end;