Skip to content

Make &FlatArray<Text> serializable #2346

Draft
isdaniel wants to merge 2 commits into
pgcentralfoundation:developfrom
isdaniel:feat/flatarray-text-serialize
Draft

Make &FlatArray<Text> serializable #2346
isdaniel wants to merge 2 commits into
pgcentralfoundation:developfrom
isdaniel:feat/flatarray-text-serialize

Conversation

@isdaniel

@isdaniel isdaniel commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Motivation

The borrowed flat-array API supported scalars and CStr, but text arrays had a long-stubbed &FlatArray<&str> placeholder unsound, since &str excludes the varlena header and breaks iteration stride. No way to serialize a borrowed text[].

Changes

  • Add Text varlena element: strides by full varlena size (varsize_any), mirroring the proven CStr element.
  • Enable borrow_serde_serialize_array fn + its pg_test.
  • rustc caps that hint list at 8 entries then prints and $N others, and the list is alphabetically sorted. Inserting Text (alphabetically between Point and Time) pushed the window forward by one, so TimestampWithTimeZone (previously 8th) dropped off into and $N others. The original fix only added Text (9 lines) without removing TimestampWithTimeZone, so it still didn't match the compiler's truncated 8-line output.

* Text varlena element for FlatArray
* Serialize FlatArray<Text>
* cover mixed-stride + empty edge cases for FlatArray<Text>
@isdaniel
isdaniel force-pushed the feat/flatarray-text-serialize branch from b3cfb3b to dd1e864 Compare July 1, 2026 10:52
Add function to calculate total length of non-null Text elements in FlatArray and add more tests for serializing FlatArray<Text>
@isdaniel
isdaniel force-pushed the feat/flatarray-text-serialize branch from dd1e864 to 882693a Compare July 2, 2026 03:26
Comment thread pgrx/src/datum/borrow.rs

/// A borrowed Postgres `text` varlena, usable as a `FlatArray` element.
#[repr(transparent)]
pub struct Text([u8]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a lifetime this can lead to UB. I think this design needs a lot more thought than I'm able to give it right now.

@isdaniel
isdaniel marked this pull request as draft July 16, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants