Registry Mirror
Skip to content

Make generate_series compatible with PostgreSQL #13316

Closed as not planned
Closed as not planned

Description

@Dandandan

Describe the bug

generate_series generates a list:

> SELECT generate_series(1,5);
+------------------------------------+
| generate_series(Int64(1),Int64(5)) |
+------------------------------------+
| [1, 2, 3, 4, 5]                    |
+------------------------------------+
1 row(s) fetched. 
Elapsed 0.003 seconds.

However PostgreSQL generates rows:

SELECT generate_series(1,5)

generate_series
-----------------
               1
               2
               3
               4
               5
(5 rows)

To Reproduce

No response

Expected behavior

I expect it to be compatible with the PostgreSQL function, besides it should also be more efficient to generate columnar data than having to unnest it.

Additional context

No response

Activity

  1. added
    bug
    on Nov 8, 2024
  2. jonathanc-n commented on Nov 8, 2024

    @jonathanc-n
    Contributor

    take

  3. 2010YOUY01 commented on Nov 9, 2024

    @2010YOUY01
    Member

    I think we can keep this behavior, and add another UDTF with the same name (which follows DuckDB behavior):

    D select generate_series(1,3);
    ┌───────────────────────┐
    │ generate_series(1, 3) │
    │        int64[]        │
    ├───────────────────────┤
    │ [1, 2, 3]             │
    └───────────────────────┘
    D select * from generate_series(1,3);
    ┌─────────────────┐
    │ generate_series │
    │      int64      │
    ├─────────────────┤
    │               1 │
    │               2 │
    │               3 │
    └─────────────────┘
    

    I think it's also easy to use: we can operate both array and table column with generate_series()
    Additionally, it would be great to let the table function only use constant memory. For example, if select * from genereate_series(1, 1000000000) it should generate data batch by batch, instead of materializing everything in TableScan node, then start output.
    This way this function can be very useful in many cases like micro benchmarks and tests.

  4. jonathanc-n commented on Nov 9, 2024

    @jonathanc-n
    Contributor

    @2010YOUY01 Yeah I agree with this, I was working on this a bit and the current generate_series logic + output seems to follow through well with the other UDFs.

  5. removed their assignment
    on Nov 11, 2024
  6. simonvandel commented on Jun 29, 2025

    @simonvandel
    Contributor

    @Dandandan Can this issue be closed now, as DataFusion supports generate_series as a table function?

  7. Jefffrey commented on Sep 27, 2025

    @Jefffrey
    Contributor

    Closed by #13540 (following duckdb behaviour)

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions