mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-18 11:45:11 +08:00
Fix DELETE command tag
DELETE on hypertables always reports 0 as affected rows. This patch fixes this issue.
This commit is contained in:
parent
f680b99529
commit
c13ed17fbc
@ -947,8 +947,8 @@ ExecModifyTable(PlanState *pstate)
|
|||||||
tupleid,
|
tupleid,
|
||||||
oldtuple,
|
oldtuple,
|
||||||
true,
|
true,
|
||||||
false,
|
|
||||||
node->canSetTag,
|
node->canSetTag,
|
||||||
|
false,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
break;
|
break;
|
||||||
|
@ -16,3 +16,44 @@ SELECT create_hypertable('test_hyper_pk', 'time');
|
|||||||
CREATE TABLE test_fk(time TIMESTAMPTZ REFERENCES test_hyper_pk(time));
|
CREATE TABLE test_fk(time TIMESTAMPTZ REFERENCES test_hyper_pk(time));
|
||||||
ERROR: foreign keys to hypertables are not supported
|
ERROR: foreign keys to hypertables are not supported
|
||||||
\set ON_ERROR_STOP 1
|
\set ON_ERROR_STOP 1
|
||||||
|
CREATE TABLE test_delete(time timestamp with time zone PRIMARY KEY, temp float);
|
||||||
|
SELECT create_hypertable('test_delete', 'time');
|
||||||
|
create_hypertable
|
||||||
|
--------------------------
|
||||||
|
(2,public,test_delete,t)
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
INSERT INTO test_delete VALUES('2017-01-20T09:00:01', 22.5);
|
||||||
|
INSERT INTO test_delete VALUES('2017-01-20T09:00:21', 21.2);
|
||||||
|
INSERT INTO test_delete VALUES('2017-01-20T09:00:47', 25.1);
|
||||||
|
INSERT INTO test_delete VALUES('2020-01-20T09:00:47', 25.1);
|
||||||
|
INSERT INTO test_delete VALUES('2021-01-20T09:00:47', 25.1);
|
||||||
|
SELECT * FROM test_delete WHERE temp = 25.1 ORDER BY time;
|
||||||
|
time | temp
|
||||||
|
------------------------------+------
|
||||||
|
Fri Jan 20 09:00:47 2017 PST | 25.1
|
||||||
|
Mon Jan 20 09:00:47 2020 PST | 25.1
|
||||||
|
Wed Jan 20 09:00:47 2021 PST | 25.1
|
||||||
|
(3 rows)
|
||||||
|
|
||||||
|
CREATE OR replace FUNCTION test_delete_row_count()
|
||||||
|
RETURNS void AS $$
|
||||||
|
DECLARE
|
||||||
|
v_cnt numeric;
|
||||||
|
BEGIN
|
||||||
|
v_cnt := 0;
|
||||||
|
|
||||||
|
DELETE FROM test_delete WHERE temp = 25.1;
|
||||||
|
GET DIAGNOSTICS v_cnt = ROW_COUNT;
|
||||||
|
|
||||||
|
IF v_cnt != 3 THEN
|
||||||
|
RAISE EXCEPTION 'unexpected result';
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
SELECT test_delete_row_count();
|
||||||
|
test_delete_row_count
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
@ -13,3 +13,30 @@ SELECT create_hypertable('test_hyper_pk', 'time');
|
|||||||
-- Foreign key constraints that reference hypertables are currently unsupported
|
-- Foreign key constraints that reference hypertables are currently unsupported
|
||||||
CREATE TABLE test_fk(time TIMESTAMPTZ REFERENCES test_hyper_pk(time));
|
CREATE TABLE test_fk(time TIMESTAMPTZ REFERENCES test_hyper_pk(time));
|
||||||
\set ON_ERROR_STOP 1
|
\set ON_ERROR_STOP 1
|
||||||
|
|
||||||
|
CREATE TABLE test_delete(time timestamp with time zone PRIMARY KEY, temp float);
|
||||||
|
SELECT create_hypertable('test_delete', 'time');
|
||||||
|
INSERT INTO test_delete VALUES('2017-01-20T09:00:01', 22.5);
|
||||||
|
INSERT INTO test_delete VALUES('2017-01-20T09:00:21', 21.2);
|
||||||
|
INSERT INTO test_delete VALUES('2017-01-20T09:00:47', 25.1);
|
||||||
|
INSERT INTO test_delete VALUES('2020-01-20T09:00:47', 25.1);
|
||||||
|
INSERT INTO test_delete VALUES('2021-01-20T09:00:47', 25.1);
|
||||||
|
SELECT * FROM test_delete WHERE temp = 25.1 ORDER BY time;
|
||||||
|
|
||||||
|
CREATE OR replace FUNCTION test_delete_row_count()
|
||||||
|
RETURNS void AS $$
|
||||||
|
DECLARE
|
||||||
|
v_cnt numeric;
|
||||||
|
BEGIN
|
||||||
|
v_cnt := 0;
|
||||||
|
|
||||||
|
DELETE FROM test_delete WHERE temp = 25.1;
|
||||||
|
GET DIAGNOSTICS v_cnt = ROW_COUNT;
|
||||||
|
|
||||||
|
IF v_cnt != 3 THEN
|
||||||
|
RAISE EXCEPTION 'unexpected result';
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
SELECT test_delete_row_count();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user