Skip to content

DuckDBPyRelation.query returns relation with full SQL string as alias #468

Closed

Description

@leostimpfle

What happens?

DuckDBPyRelation.query seems to set the alias of the returned relation to the full SQL string generating the relation. Is this intentional?

This causes problems when chaining query calls as below: step2 fails because step1.alias is a SQL expression. This is surprising because data.alias is a generic name such as 'unnamed_relation_1a0134771ca80911'.

Possibly related to duckdb/duckdb#13672.

To Reproduce

import duckdb

con = duckdb.connect()
con.execute("CREATE TABLE raw (year INT, facility VARCHAR, value DOUBLE)")
con.execute("INSERT INTO raw VALUES (2020, 'F001', 1.0), (2021, 'F001', 2.0)")

data = con.sql("SELECT * FROM raw")
step1 = data.query(data.alias, f"SELECT *, value * 2 AS doubled FROM {data.alias}")
step2 = data.query(step1.alias, f"SELECT *, doubled + 1 AS incremented FROM {step1.alias}")  # This fails with _duckdb.ParserException: Parser Error: syntax error at or near "SELECT"

OS:

OSX

DuckDB Package Version:

1.5.1

Python Version:

3.14

Full Name:

Leonard Stimpfle

Affiliation:

Ghent University

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration to reproduce the issue?

  • Yes, I have

Activity

  1. leostimpfle commented on Jun 30, 2026

    @leostimpfle
    ContributorAuthor

    I think this is caused by inadvertently reversed arguments to QueryRelation. See details in #521. @evertlammerts please let me know if there are any issues with the PR

  2. added 4 commits that reference this issue on Jul 1, 2026
    1b70332
    ea34b03
    f488eea
    378e182
  3. evertlammerts commented on Jul 1, 2026

    @evertlammerts
    Member

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions