Skip to content

DB:Exception: Qualified matcher reservation.* found a non-compound expression #82151

Closed

Description

@apausepi

Company or project name

Profit Intelligence

Question

Hello Support Team,

I have this query

WITH
    reservations_enriched as
        (SELECT reservations.*
         FROM datasources_guesty.import_reservations reservations
         WHERE reservations.unit_id = 1585),

    stays as
        (SELECT 1 as reservations
         FROM reservations_enriched)
SELECT *
FROM stays

In import_reservations table I don't have column named reservations.

When I execute it I have this error
Image

To fix it

  • I can apply SETTING allow_experimental_analyzer = 0 (but I would avoid)
  • I can rename one alias reservations by another name (but I don't understand the reason)

I would like to know the reason and how to fix it properly

Version info

Activity

  1. morsapaes commented on Jun 19, 2025

    @morsapaes
    Contributor

    The new analyzer is stricter about scope resolution. In your query, the call to reservations_enriched in the stays CTE causes ClickHouse to try and resolve reservations.*, which in that context disambiguates to the reservations column in the current scope — a single column of type UInt8.

    The simplest way to rewrite your query is to replace reservations.* with *. Not sure what you're trying to achieve with this query, but there's a chance it could be optimized to reduce the amount of data scanned if all you need is a membership check that stops at the first match.

    Closing, but tagging @KochetovNicolai for a second pair of eyes in case I'm misinterpreting the behavior of the new analyzer.

  2. apausepi commented on Jun 19, 2025

    @apausepi
    Author

    Thanks,

    It's a simple sample here, just to reproduce the issue.
    We finally replaced reservations.* by the columns we need directly (we can't use * in our final query, many left join..)

  3. den-crane commented on Jun 20, 2025

    @den-crane
    Contributor

    @morsapaes

    MariaDB [dw]> WITH
        ->     reservations_enriched as
        ->         (SELECT reservations.*
        ->          FROM (select 1585 as unit_id, 2 as y) reservations
        ->          WHERE reservations.unit_id = 1585),
        ->
        ->     stays as
        ->         (SELECT 1 as reservations FROM reservations_enriched)
        -> SELECT *
        -> FROM stays;
    +--------------+
    | reservations |
    +--------------+
    |            1 |
    +--------------+
    1 row in set (0.000 sec)
    
    psql> WITH
        reservations_enriched as
            (SELECT reservations.*
             FROM (select 1585 as unit_id, 2 as y) reservations
             WHERE reservations.unit_id = 1585),
    
        stays as
            (SELECT 1 as reservations FROM reservations_enriched)
    SELECT *
    FROM stays;
                1
    
    ./duckdb
    v0.8.1 6536a77232
    Enter ".help" for usage hints.
    Connected to a transient in-memory database.
    Use ".open FILENAME" to reopen on a persistent database.
    D WITH
    >     reservations_enriched as
    >         (SELECT reservations.*
    >          FROM (select 1585 as unit_id, 2 as y) reservations
    >          WHERE reservations.unit_id = 1585),
    >
    >     stays as
    >         (SELECT 1 as reservations FROM reservations_enriched)
    > SELECT *
    > FROM stays;
    ┌──────────────┐
    │ reservations │
    │    int32     │
    ├──────────────┤
    │            1 │
    └──────────────┘
    
  4. added
    analyzer
    on Jun 25, 2025
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

    analyzerquestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions