Skip to content

Return at least one row #10090

@cosmin-mogos

Description

@cosmin-mogos

We have a simple druid sql query to return the count of some events.

select count(*) from events where type='the event'

The problem is that if no events match the query no rows are returned, since we use it for alerts we'd like the query above to return a row with 0 value in case no events match the where clause. How can we achieve this?

The closest I managed was with

select sum(c) from (
    select count(*) as c from events where type='the event'
    union all
    select 0 as c from events limit 1
)

which fails with Cannot build plan for query, but succeeds if the sum(c) is replaced with just c.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions