Skip to content

Repeat scalar function panics on negative repeat counts. #10759

@tshauck

Description

@tshauck

Describe the bug

The repeat scalar function currently panics causing a capacity overflow error for negative numbers.

To Reproduce

SELECT repeat('hi', -1)
thread 'main' panicked at library/alloc/src/slice.rs:503:50:
capacity overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

Postgres and Spark both appear to return empty strings when presented with a negative number.


postgres=# SELECT LENGTH(repeat('hi', -1));
 length 
--------
      0
(1 row)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions