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

Slony-I 2.2.10 Documentation
Prev | Fast Backward | Chapter 8. Schema schemadoc | Fast Forward | Next

# 8.97. sequencesetvalue(p_ignore_missing integer, p_last_value integer, p_ev_seqno bigint, p_seq_origin bigint, p_seq_id boolean)

Function Properties

Language: PLPGSQL

Return Type: integer

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

    declare
    	v_fqname			text;
    	v_found                         integer;
    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
    	        if p_ignore_missing then
                           return null;
                    end if;
    		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 || ')';

    	if p_ev_seqno is not null then
    	   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);
    	end if;
    	return p_seq_id;
    end;

Prev | Home | Next
sequencelastvalue(p_seqname text) | Up | setaddsequence(p_seq_comment integer, p_fqname integer, p_seq_id text, p_set_id text)