Skip to content

Native support for non-text column types (JSONB, ARRAY, BYTEA, UUID) #9

Description

@cl8dep

Summary

All sanitization strategies operate by casting column values to ::text. Columns of type JSONB, BYTEA, ARRAY, UUID, range types, and others are not explicitly handled and may produce incorrect results or runtime errors when cast.

Current Limitation

For example, hash strategy generates:

encode(sha256("column"::text::bytea), 'hex')

On a JSONB column this produces a hash of the JSON text representation, which is semantically correct. But BYTEA columns would produce a hex-encoded hash of the binary's text encoding, not the binary itself.

faker strategies assign text values that may fail type casting on strictly-typed columns.

Proposed Approach

  1. Type-aware SQL generation in each strategy: detect column data type during validation and emit type-appropriate SQL (e.g., sha256(column) directly for bytea, uuid_generate_v4() for UUID, '{}'::jsonb for JSONB null replacement).
  2. New faker methods for typed columns: faker: uuid, faker: jsonb_empty, faker: bytea_empty.
  3. Validation warning when a strategy is applied to a column type it does not natively support.

Affected Types

Type Current Behavior Needed
JSONB Casts to text, works but lossy Native JSON manipulation support
BYTEA May corrupt binary data Direct binary handling
UUID Works via text cast Native uuid_generate_v4()
ARRAY Likely fails or corrupts Per-element sanitization
Range types Unsupported New strategy or raw_sql

Acceptance Criteria

  • validate reports a warning when a strategy is applied to an unsupported column type
  • hash strategy works correctly on BYTEA columns
  • null_value works correctly on all nullable types
  • faker: uuid generates valid UUIDs for UUID columns
  • faker strategies that return text emit a validation warning on non-text columns

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions