Skip to content

[Bug]: AL05 false positive - JSON arrow operator (->) not recognized as alias reference #2327

@hongbo-miao

Description

@hongbo-miao

What happened?

with stanza as (
    select
        data -> 'name' as name,
        data -> 'backup' -> (
            jsonb_array_length(data -> 'backup') - 1
        ) as last_backup,
        data -> 'archive' -> (
            jsonb_array_length(data -> 'archive') - 1
        ) as current_archive
    from jsonb_array_elements(monitor.pgbackrest_info()) as data
)

select
    name,
    to_timestamp(
        (last_backup -> 'timestamp' ->> 'stop')::numeric
    ) as last_successful_backup,
    current_archive ->> 'max' as last_archived_wal
from stanza;

Expected: No error - data alias is used in data -> 'name'

Actual:

sqruff auto fix removes as data inside from jsonb_array_elements(monitor.pgbackrest_info()) as data

FAIL
L:  13 | P:  61 | AL05 | Alias 'data' is never used in SELECT statement.
                       | [aliasing.unused]

However, it should not.

Seems qruff does not parse PostgreSQL JSON operators (->, ->>) as identifier references.

Version

0.34.1

Checked in Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions