eperusteet
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
insertasrevision(tablename text, id bigint, _rev integer)
Parameters
Name
Type
Mode
tablename
text
IN
id
bigint
IN
_rev
integer
IN
Definition
DECLARE cnames text[]; BEGIN SELECT array_agg(quote_ident(column_name) ORDER BY ordinal_position) INTO cnames FROM information_schema.columns WHERE table_name = tableName; EXECUTE 'INSERT INTO ' || quote_ident(tableName || '_aud') || '(' || array_to_string(cnames, ', ') || ', rev, revtype) SELECT v.*, $2 as rev, 0 as revtype FROM ' || quote_ident(tableName) || ' v WHERE v.id = $1 AND NOT EXISTS( select a.rev from ' || quote_ident(tableName || '_aud') || ' a where a.id = $1 and a.rev = $2 )' USING id, _rev; RETURN _rev; END