drop extension if exists pg_query_rewrite; -- create extension pg_query_rewrite; select pgqr_truncate(); pgqr_truncate --------------- t (1 row) -- drop table if exists t; create table t(x int, y int); -- insert into t values(1,2); -- select pgqr_add_rule('select 10;','select 11;'); pgqr_add_rule --------------- t (1 row) select pgqr_add_rule('select 1+1;','select 1+2;'); pgqr_add_rule --------------- t (1 row) select pgqr_add_rule('select x from t;','select x,y from t;'); pgqr_add_rule --------------- t (1 row) -- select 10; ?column? ---------- 11 (1 row) select 1+1; ?column? ---------- 3 (1 row) select x from t; x | y ---+--- 1 | 2 (1 row) -- select pgqr_remove_rule('select 1+1;'); pgqr_remove_rule ------------------ t (1 row) select pgqr_rules(); pgqr_rules ---------------------------------------------------------------------------------------------------- (datname=contrib_regression,"source=select 10;","target=select 11;",rewrite_count=1) (datname=contrib_regression,"source=select x from t;","target=select x,y from t;",rewrite_count=1) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (10 rows) select 1+1; ?column? ---------- 2 (1 row) -- select pgqr_remove_rule('select 10;'); pgqr_remove_rule ------------------ t (1 row) select pgqr_rules(); pgqr_rules ---------------------------------------------------------------------------------------------------- (datname=contrib_regression,"source=select x from t;","target=select x,y from t;",rewrite_count=1) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (10 rows) select 10; ?column? ---------- 10 (1 row) -- select pgqr_remove_rule('select x from t;'); pgqr_remove_rule ------------------ t (1 row) select pgqr_rules(); pgqr_rules -------------------------------------------------------- (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (datname=NULL,source=NULL,target=NULL,rewrite_count=0) (10 rows) select x from t; x --- 1 (1 row) -- select x from t; x --- 1 (1 row) select 1+1; ?column? ---------- 2 (1 row) select 10; ?column? ---------- 10 (1 row)