[GENERAL] Atomicity of INSERT INTO ... SELECT ... WHERE NOT EXISTS ...

2014-08-27 Thread Jim Garrison
Given (pseudocode) CREATE TABLE kvstore ( k varchar primary key, v varchar); CREATE OR REPLACE FUNCTION store_key_value_pair(k varchar, v varchar) returns boolean as $$ BEGIN INSERT INTO kvstore (k, v) SELECT :k, :v WHERE NOT EXISTS (select 1 from kv

[GENERAL] Complex Recursive Query

2014-07-23 Thread Jim Garrison
I have a collection of relationship rows of the form Table: graph key1 varchar key2 varchar A row of the form ('a','b') indicates that 'a' and 'b' are related. The table contains many relationships between keys, forming several disjoint sets. All relationships are bi-directional, and both

[GENERAL] Remote troubleshooting session connection?

2014-04-04 Thread Jim Garrison
I'm working on an ETL system that is driven from Java/JDBC but is implemented mostly as SQL queries against a PostgreSQL database. An ETL "job" runs inside its own transaction and consists of a series of queries that transform the data from staging tables to the destination tables. If a fail