From: princekumar1291 (@princekumar1291) <noreply+princekumar1291@github.com>
To: pgpartman/pg_partman <noreply+pgpartman-pg_partman@github.com>
Subject: [pgpartman/pg_partman] PR #881: Fix format argument references in partition_data_time lock-wait branch
Date: Fri, 09 Oct 2026 08:08:46 +0000
Message-ID: <gh-pgpartman-pg_partman-881@github.com> (raw)
## Summary
Fix the `format()` argument references in the `p_lock_wait > 0` branch of `partition_data_time()`.
The existing expression supplies five arguments but references `%6$L`, which raises `too few arguments for format()` when the source contains data. It also uses `%4$s` for the partition expression, although argument 4 is the lower timestamp bound. Use explicit positional placeholders throughout: schema `%1$I`, table `%2$I`, expression `%3$s`, lower bound `%4$L`, and upper bound `%5$L`.
This leaves the existing `FOR UPDATE NOWAIT` and retry logic unchanged.
## Regression coverage
Add a transactional pgTAP test covering:
- Nonempty DEFAULT migration with `p_lock_wait := 2`, including creation of missing monthly partitions.
- ASC and DESC processing and preservation of the next month's rows between batches.
- Mixed-case schema, table, and control-column identifiers.
- Migration from an explicit source table with a positive lock wait.
- Existing `p_lock_wait := 0` behavior and row/payload preservation.
## Validation
Tested against an isolated local PostgreSQL 18.6 instance with pgTAP 1.3.5:
- Unpatched development source: the new test fails at its first positive-lock-wait migration with `too few arguments for format()`.
- Patched source: new regression test passes all 14 assertions.
- Existing `test-time-monthly.sql`: 121 assertions pass.
- Existing `test-time-daily.sql`: 221 assertions pass.
- Existing `test-time-mixed-case.sql`: 222 assertions pass.
- `git diff --check` passes.
The full suite and PostgreSQL 14–17 were not run locally; the repository's existing CI matrix can provide that coverage. Concurrent row-lock retry behavior was not separately tested; this patch does not change that logic.
## Release integration
This PR changes the canonical function source and tests only. I have not modified an already-published upgrade script or chosen the next release version. Please include the corrected function definition in the next extension upgrade script so existing installations receive the fix too.
inline patch 1: sql/functions/partition_data_time.sql, test/test-time-lock-wait.sql (+63/-2 lines) download inline-1.patchdiff --git a/sql/functions/partition_data_time.sql b/sql/functions/partition_data_time.sqlindex fb441ab..f51b523 100644--- a/sql/functions/partition_data_time.sql+++ b/sql/functions/partition_data_time.sql@@ -283,7 +283,7 @@ FOR i IN 1..p_batch_count LOOP
WHILE v_lock_iter <= 5 LOOP
v_lock_iter := v_lock_iter + 1;
BEGIN
- v_sql := format('SELECT * FROM ONLY %I.%I WHERE %s >= %L AND %4$s < %6$L FOR UPDATE NOWAIT'+ v_sql := format('SELECT * FROM ONLY %1$I.%2$I WHERE %3$s >= %4$L AND %3$s < %5$L FOR UPDATE NOWAIT'
, v_source_schemaname
, v_source_tablename
, v_partition_expression
@@ -404,4 +404,3 @@ RETURN v_total_rows;
END
$$;
-diff --git a/test/test-time-lock-wait.sql b/test/test-time-lock-wait.sqlnew file mode 100644index 0000000..696622d--- /dev/null+++ b/test/test-time-lock-wait.sql@@ -0,0 +1,62 @@+-- Exercise the positive lock-wait branch with nonempty DEFAULT and source tables.+\set ON_ERROR_ROLLBACK 1+\set ON_ERROR_STOP true++BEGIN;+SELECT set_config('search_path', 'partman, public', false);+SELECT set_config('TimeZone', 'UTC', true);+SELECT plan(14);++CREATE SCHEMA "Partman Lock Test";+CREATE TABLE "Partman Lock Test"."Monthly Data" (+ id integer NOT NULL,+ payload text NOT NULL,+ "Expires On" timestamptz NOT NULL+) PARTITION BY RANGE ("Expires On");++SELECT create_partition('Partman Lock Test.Monthly Data', 'Expires On', '1 month');++INSERT INTO "Partman Lock Test"."Monthly Data" VALUES+ (1, 'first month', (date_trunc('month', CURRENT_TIMESTAMP) + interval '2 years')::date),+ (2, 'second month', (date_trunc('month', CURRENT_TIMESTAMP) + interval '2 years 1 month')::date);++SELECT is((SELECT count(*) FROM ONLY "Partman Lock Test"."Monthly Data_default"),+ 2::bigint, 'Future rows initially route to DEFAULT');+SELECT is(partition_data_time('Partman Lock Test.Monthly Data', p_lock_wait := 2),+ 1::bigint, 'Positive lock wait migrates the first monthly batch');+SELECT is((SELECT count(*) FROM ONLY "Partman Lock Test"."Monthly Data_default"),+ 1::bigint, 'The upper bound leaves the second month in DEFAULT');+SELECT is(partition_data_time('Partman Lock Test.Monthly Data', p_lock_wait := 2, p_order := 'DESC'),+ 1::bigint, 'Positive lock wait also works in descending order');+SELECT is((SELECT count(*) FROM ONLY "Partman Lock Test"."Monthly Data_default"),+ 0::bigint, 'DEFAULT is empty after both batches');+SELECT is((SELECT count(*) FROM "Partman Lock Test"."Monthly Data"),+ 2::bigint, 'The parent still exposes both rows');+SELECT results_eq('SELECT id, payload FROM "Partman Lock Test"."Monthly Data" ORDER BY id',+ $$VALUES (1, 'first month'::text), (2, 'second month'::text)$$,+ 'Migration preserves row values');++CREATE TABLE "Partman Lock Test"."Source Data" (LIKE "Partman Lock Test"."Monthly Data");+INSERT INTO "Partman Lock Test"."Source Data" VALUES+ (3, 'source row', (date_trunc('month', CURRENT_TIMESTAMP) + interval '2 years 2 months')::date);+SELECT is(partition_data_time('Partman Lock Test.Monthly Data', p_lock_wait := 2,+ p_source_table := 'Partman Lock Test.Source Data'),+ 1::bigint, 'Positive lock wait also migrates an explicit source table');+SELECT is((SELECT count(*) FROM "Partman Lock Test"."Source Data"),+ 0::bigint, 'The explicit source is drained');+SELECT is((SELECT count(*) FROM "Partman Lock Test"."Monthly Data"),+ 3::bigint, 'Source migration adds the row to the parent');++INSERT INTO "Partman Lock Test"."Monthly Data" VALUES+ (4, 'zero wait row', (date_trunc('month', CURRENT_TIMESTAMP) + interval '2 years 3 months')::date);+SELECT is((SELECT count(*) FROM ONLY "Partman Lock Test"."Monthly Data_default"),+ 1::bigint, 'A new future row routes to DEFAULT');+SELECT is(partition_data_time('Partman Lock Test.Monthly Data', p_lock_wait := 0),+ 1::bigint, 'Zero lock wait remains functional');+SELECT is((SELECT count(*) FROM ONLY "Partman Lock Test"."Monthly Data_default"),+ 0::bigint, 'Zero lock wait drains DEFAULT');+SELECT is((SELECT count(*) FROM "Partman Lock Test"."Monthly Data"),+ 4::bigint, 'All four rows remain visible through the parent');++SELECT * FROM finish();+ROLLBACK;