Skip to content

MasonM/postgres_select_tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postgres_select_tracker

PL/pgSQL functions to copy rows that are selected from a given table(s) to a separate tracking table. Meant to help prune unused rows from datasets used for testing, but could also be useful for auditing purposes. Inspired by this post by Fabrízio de Royes Mello.

Example:

\i /pgst/pgst_install.sql

CREATE TABLE test(col int);
INSERT INTO test VALUES (1), (2), (3);
SELECT pgst_start_for_table('test');

SELECT * FROM test WHERE col < 3;
-- Will return rows 1 and 2

SELECT * FROM test_pgst_track;
-- Will also return rows 1 and 2

Caveats

  1. After calling pgst_start_for_table(<table_name>);, all selects to the table will have an extra column (which can be ignored)
  2. Won't work with tables joined to other tables by an index, because the tracking function will cause PostgreSQL to ignore the index and do a sequential scan.

About

PL/pgSQL functions to record selected rows to a separate table

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors