Skip to content

Conversation

@mattklein
Copy link

Fixes #828

Problem

The partition_data_proc function failed when called with p_order := 'DESC' and a p_interval parameter, causing errors like:
ERROR: relation "my_table_p20251105" does not exist

Root Cause

The code incorrectly used = (comparison operator) instead of := (assignment operator) in PL/pgSQL. This caused variable assignments to be evaluated as boolean comparisons and discarded, rather than actually updating the
variables.

Solution

Changed all affected instances of = to := for proper variable assignments in:

  • partition_data_time.sql line 252: v_min_partition_timestamp assignment for DESC order with batch intervals
  • partition_data_id.sql lines 154, 168, 174: v_min_partition_id assignments for both ASC and DESC order

Testing

The fix ensures that when using DESC order, the partition boundary calculations correctly respect the partition interval (e.g., monthly) rather than defaulting to incorrect daily boundaries.

Fixed incorrect use of comparison operator (=) instead of assignment
operator (:=) in partition_data_time and partition_data_id functions
when processing data in DESC order with batch intervals.

This bug caused variable assignments to be treated as boolean
comparisons that were evaluated and discarded, preventing proper
calculation of partition boundaries when using p_order := 'DESC'.

Affected locations:
- partition_data_time.sql line 252: v_min_partition_timestamp assignment
- partition_data_id.sql line 154: v_min_partition_id assignment (ASC)
- partition_data_id.sql line 168: v_min_partition_id assignment (DESC)
- partition_data_id.sql line 174: v_min_partition_id batch adjustment

This resolves issue pgpartman#828 where partition_data_proc would fail with
"relation does not exist" errors when called with p_order := 'DESC'
and a p_interval parameter on monthly partitioned tables.
@mattklein
Copy link
Author

NOTE: PR generated by Claude Code based on the issue I'd written up here. Admittedly I'm not a PL/SQL expert so I'm not sure this is a valid fix, and I haven't build/tested this myself, but submitting it in the hopes it'll be useful to the maintainers.

Btw I've loved my first experience with pg_partman!

@keithf4 keithf4 self-assigned this Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

p_order := DESC causes partition_data_proc to fail

2 participants