I use PostgreSQL 9.5, Ubuntu 16.04
I have an empty table:
CREATE TABLE IF NOT EXISTS candles_1m(
timestamp REAL PRIMARY KEY,
open REAL,
close REAL,
high REAL,
low REAL,
volume REAL
);
Then I try to do multiple upsert (without duplicates of 'timestamp' - the primary key):
INSERT INTO candles_1m (
timestamp, open, close, high, low, volume
) VALUES
(1507804800, 5160, 5158.7, 5160, 5158.7, 5.40608574),
(1507804740, 5157.5, 5160, 5160, 5156.1, 39.03357813),
(1507804680, 5156.5, 5157.4, 5157.4, 5156, 33.54458319),
(1507804620, 5151.3, 5156.5, 5157.5, 5151.2, 19.75590599)
ON CONFLICT (timestamp)
DO UPDATE SET
open = EXCLUDED.open,
close = EXCLUDED.close,
high = EXCLUDED.high,
low = EXCLUDED.low,
volume = EXCLUDED.volume;
And I received and error:
ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time
HINT: Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
I do not understand why? I don't have duplicates there! But my next step will be create a request that will add (or update) each of rows step by step (independent of duplicates exist).
SELECT 1507804800::REAL = 1507804740::REALresult isTRUEtimestamp!! Using a floating point data type as a primary key is ... scrary, at least.