Skip to content

Parametrized view - Is it possible to use parameter in subquery (maybe there is an issue with array)? #68041

Closed

Description

@chaos827

Company or project name

No response

Question

I tried use parameter with array, this is my view definition

CREATE OR REPLACE VIEW Test AS
SELECT * FROM myTable WHERE AccountId IN {AccountIds: Array(Int32)}

it is works well with below query:

SELECT * FROM Test(AccountIds =[1, 2, 3])

and then I want to use subquery to generate AccountId list:

SELECT * FROM Test(AccountIds = (SELECT groupArray(AccountId) FROM AccountTable)),

the ClickHouse throws exceptions:

SQL Error [456] [07000]: Code: 456. DB::Exception: Substitution AccountIds is not set. (UNKNOWN_QUERY_PARAMETER) (version 24.5.1.1763 (official build))
, server ClickHouseNode [uri=https://4.149.226.200:8443/default, options={sslmode=NONE,use_server_time_zone=false,sslkey=*,sslcert=,use_time_zone=false,sslrootcert=}]@-1117104610.

I tried many ways, but the query still does not work.

what' more when I use array(1,2, 3) replace [1,2 ,3], the ClickHouse also raises exception:

SQL Error [62] [07000]: Code: 62. DB::Exception: Syntax error: failed at position 136 (')') (line 3, col 132): )
. Expected end of query. (SYNTAX_ERROR) (version 24.5.1.1763 (official build))

could you please take a look how to use parameterized view with subquery and array parameters? many thanks.

Version info

Activity

  1. added
    bug
    and removed
    question
    on Jul 24, 2026
  2. PedroTadim commented on Jul 24, 2026

    @PedroTadim
    Member
  3. groeneai commented on Jul 24, 2026

    @groeneai
    Collaborator

    @PedroTadim acknowledged. I'll reproduce both cases from the fiddle on current master (the subquery-valued parameter giving UNKNOWN_QUERY_PARAMETER, and array(1,2,3) giving SYNTAX_ERROR), root-cause them, and follow up here with a fix PR for your review.

  4. groeneai commented on Jul 24, 2026

    @groeneai
    Collaborator

    @PedroTadim opened #111790 for this.

    Root cause: when a parameterized view is called with a subquery-valued argument of type Array/Tuple/LowCardinality, scalar subquery optimization keeps the value as a __getScalar reference instead of a literal, so the analyzer's parameterized-view arg collection (which only accepts a ConstantNode) drops it and the query fails with UNKNOWN_QUERY_PARAMETER. Scalar types (e.g. Int32) fold to a literal and always worked.

    The array(1, 2, 3) function form from the report already works on current master; the remaining failure was the subquery form. The fix folds the scalar subquery to a literal only while resolving a parameterized-view argument.

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