Skip to content

Instantly share code, notes, and snippets.

@bliiir
Created November 18, 2018 15:27
Show Gist options
  • Save bliiir/5cb0b360ace7b43986990f903baca8c8 to your computer and use it in GitHub Desktop.
Save bliiir/5cb0b360ace7b43986990f903baca8c8 to your computer and use it in GitHub Desktop.
Postgres database: Merge two tables using composite key constraints and Insert statement in what is know as an UPSERT
INSERT INTO bucket(
market_id,
timeframe_id,
time_close,
price_open,
price_high,
price_low,
price_close,
volume)
SELECT
market_id,
timeframe_id,
time_close,
price_open,
price_high,
price_low,
price_close,
volume
FROM bucket_temp
ON CONFLICT (market_id, timeframe_id, time_close) DO NOTHING;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment