Hi,
Using a single node CrateDB (v5.3.1) install, am getting unexpected behaviour when attempting to use “ON CONFLICT” when inserting. Has anyone else experience with this?
/***************
* Testing INSERT ON CONFLICT UPDATE SET
***************/
drop table if exists history_tsx
;
CREATE TABLE history_tsx (
name TEXT NOT NULL,
pointType TEXT NOT NULL,
timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
ts_day TIMESTAMP WITH TIME ZONE GENERATED ALWAYS AS date_trunc('day', timestamp),
stringValue VARCHAR(255),
value DOUBLE precision,
primary key ("name", "ts_day", "timestamp")
) PARTITIONED BY (ts_day)
WITH (number_of_routing_shards = 4, number_of_replicas = 0, "write.wait_for_active_shards" = 1)
;
REFRESH TABLE history_tsx
;
INSERT INTO history_tsx
("name", "pointtype", "timestamp", "value") VALUES
('DEVICES.1 ', 'Application Point', '2023-05-01T16:37:59.7880000Z', 559)
;
REFRESH TABLE history_tsx
;
INSERT INTO history_tsx
("name", "pointtype", "timestamp", "value") VALUES
('DEVICES.1 ', 'Application Point', '2023-05-01T16:37:59.7880000Z', 999)
ON CONFLICT ("name", "ts_day", "timestamp") DO UPDATE SET
value = excluded."value"
;
REFRESH TABLE history_tsx
;
INSERT INTO history_tsx
("name", "pointtype", "timestamp", "value") VALUES
('DEVICES.2 ', 'Application Point', '2023-05-02T16:37:59.7880000Z', 559),
('DEVICES.2 ', 'Application Point', '2023-05-02T16:37:59.7880000Z', 999)
;
REFRESH TABLE history_tsx
;
INSERT INTO history_tsx
("name", "pointtype", "timestamp", "value") VALUES
('DEVICES.3 ', 'Application Point', '2023-05-03T16:37:59.7880000Z', 559),
('DEVICES.3 ', 'Application Point', '2023-05-03T16:37:59.7880000Z', 999)
ON CONFLICT (name, ts_day, timestamp) DO UPDATE SET
value = excluded."value"
;
REFRESH TABLE history_tsx
;
select "name", "ts_day", "timestamp", value
FROM history_tsx
;
-------------------------------------------------------------------
-- What I saw:
name |ts_day |timestamp | value|
-----------+-----------------------+-----------------------+------+
DEVICES.1 |2023-05-01 01:00:00.000|2023-05-01 17:37:59.788| 559.0|
DEVICES.2 |2023-05-02 01:00:00.000|2023-05-02 17:37:59.788| 559.0|
-------------------------------------------------------------------
-- What I expected to see:
name |ts_day |timestamp | value|
-----------+-----------------------+-----------------------+------+
DEVICES.1 |2023-05-01 01:00:00.000|2023-05-01 17:37:59.788| 999.0|
DEVICES.2 |2023-05-02 01:00:00.000|2023-05-02 17:37:59.788| 559.0|
DEVICES.3 |2023-05-03 01:00:00.000|2023-05-02 17:37:59.788| 999.0|
-------------------------------------------------------------------