Skip to content

Support PostgreSQL numeric promotion and missing numeric operators #63

Description

@alexeichhorn

Context

dbkit supports same-type numeric +, -, and *, but does not model PostgreSQL's broader numeric promotion and operator matrix.

Scope

Mixed numeric promotion

Support PostgreSQL-valid pairs such as:

SMALLINT + INTEGER         → INTEGER
INTEGER + BIGINT           → BIGINT
REAL + DOUBLE PRECISION    → DOUBLE PRECISION

Apply the same base-result matrix to +, -, and * in both supported operand directions.

Division and remainder

Add typed / and % expression support with PostgreSQL's result types and error behavior.

Conditional numeric functions

Use the common numeric type for calls such as:

COALESCE(integer_value, bigint_value)
GREATEST(smallint_value, integer_value)
LEAST(real_value, double_value)

Small integer widening

Allow i16 / Option<i16> in interval::days, hours, and minutes, where PostgreSQL widens SMALLINT to the INTEGER constructor argument.

Requirements

  • Preserve Option<Output> whenever any SQL-propagating operand is nullable.
  • Reject numeric/non-numeric combinations at compile time.
  • Centralize the promotion matrix rather than duplicating it per operator/function.
  • Cover both operand directions and boundary types.

This is separate from #46, which corrects the already-supported SMALLINT op SMALLINT result, and #49, which covers aggregate SUM result types.

Activity

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions