Skip to content

[Bug]: COPY into hypertable does not respect REJECT_LIMIT in PG18Β #10855

Closed

Description

@RobAtticus

What type of bug is this?

Incorrect result

What subsystems and features are affected?

Command processing

What happened?

Building off of #10854 , in PG18 REJECT_LIMIT was added to tell COPY how many errors were acceptable before the COPY itself needed to error & rollback. The COPY implementation in TimescaleDB ignores it so it will copy in all the rows (with incorrect results due to #10854) without rolling back. Reproducer script attached.

TimescaleDB version affected

2.30.2

PostgreSQL version used

18+

What operating system did you use?

Any

What installation method did you use?

Not applicable

What platform did you run on?

Not applicable

Relevant log output and stack trace

version
------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 18.6 (Ubuntu 18.6-1.pgdg26.04+2) on aarch64-unknown-linux-gnu, compiled by gcc (Ubuntu 15.2.0-16ubuntu1) 15.2.0, 64-bit
(1 row)

 timescaledb_version
---------------------
 2.32.0-dev
(1 row)

DO
BEGIN
SET
CREATE SCHEMA
CREATE TABLE
CREATE TABLE
          create_hypertable
-------------------------------------
 (3,copy_reject_limit_repro,hyper,t)
(1 row)

SAVEPOINT
psql:/var/tmp/tsdb-copy-audit/02_reject_limit.sql:40: ERROR:  skipped more than REJECT_LIMIT (1) rows due to data type incompatibility
CONTEXT:  COPY plain, line 4, column val: "bad_value"
ROLLBACK
RELEASE
SAVEPOINT
COPY 5
RELEASE
 table_kind | copy_sqlstate | rows_after_copy
------------+---------------+-----------------
 plain      | 22P02         |               0
 hypertable | 00000         |               5
(2 rows)

ROLLBACK

How can we reproduce the bug?

-- Reproduce COPY FROM ... REJECT_LIMIT failing to enforce the error limit.
-- Requires PostgreSQL 18+ and TimescaleDB installed/preloaded in this database.
-- Run: psql -X -f 02_reject_limit.sql DATABASE
-- Two invalid rows exceed REJECT_LIMIT 1. BOTH COPY commands should fail
-- with SQLSTATE 22P02 and leave zero rows in their respective tables.
-- Affected hypertables instead report COPY 5 and retain five rows.
-- Everything created by this script is rolled back at the end.

\set ON_ERROR_STOP on
SELECT version();
SELECT extversion AS timescaledb_version
FROM pg_extension WHERE extname = 'timescaledb';

DO $$
BEGIN
    IF current_setting('server_version_num')::integer < 180000 THEN
        RAISE EXCEPTION 'This reproducer requires PostgreSQL 18 or newer: REJECT_LIMIT was introduced in PG18';
    END IF;
END
$$;

BEGIN;
SET LOCAL timezone = 'UTC';
CREATE SCHEMA copy_reject_limit_repro;
CREATE TABLE copy_reject_limit_repro.plain (ts timestamptz NOT NULL, val integer);
CREATE TABLE copy_reject_limit_repro.hyper (LIKE copy_reject_limit_repro.plain);
SELECT create_hypertable('copy_reject_limit_repro.hyper', 'ts',
                        chunk_time_interval => INTERVAL '7 days');

-- Savepoints allow us to inspect each table after the expected COPY error.
-- Recover only when COPY fails, so an incorrectly successful load stays visible.
SAVEPOINT plain_copy;
\set ON_ERROR_STOP off
COPY copy_reject_limit_repro.plain FROM STDIN (FORMAT csv, ON_ERROR ignore, REJECT_LIMIT 1);
2024-01-01 00:00:00+00,1
2024-01-01 01:00:00+00,not_a_number
2024-01-02 00:00:00+00,3
2024-01-08 00:00:00+00,bad_value
2024-01-15 00:00:00+00,5
\.
\set plain_sqlstate :SQLSTATE
\if :ERROR
ROLLBACK TO SAVEPOINT plain_copy;
\endif
\set ON_ERROR_STOP on
RELEASE SAVEPOINT plain_copy;

SAVEPOINT hyper_copy;
\set ON_ERROR_STOP off
COPY copy_reject_limit_repro.hyper FROM STDIN (FORMAT csv, ON_ERROR ignore, REJECT_LIMIT 1);
2024-01-01 00:00:00+00,1
2024-01-01 01:00:00+00,not_a_number
2024-01-02 00:00:00+00,3
2024-01-08 00:00:00+00,bad_value
2024-01-15 00:00:00+00,5
\.
\set hyper_sqlstate :SQLSTATE
\if :ERROR
ROLLBACK TO SAVEPOINT hyper_copy;
\endif
\set ON_ERROR_STOP on
RELEASE SAVEPOINT hyper_copy;

SELECT 'plain' AS table_kind, :'plain_sqlstate' AS copy_sqlstate, count(*) AS rows_after_copy
FROM copy_reject_limit_repro.plain
UNION ALL
SELECT 'hypertable', :'hyper_sqlstate', count(*)
FROM copy_reject_limit_repro.hyper;
ROLLBACK;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugv2.30.2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions