Skip to content

Complex SQL query which works with precompiled 0.13.2, returns syntax error with latest compiled code #1588

@dardhal

Description

@dardhal

lnav version
Issue occurs with "lnav 0.14.0-a2e2380-dirty" compiled from source, but it does not with "lnav 0.13.2" downloaded as statically linked binary from GitHub.

Describe the bug
I have lists of files in a format which is like below:

name    mtime   fileid  size    seg_bytes       seg_count       redun_seg_count pre_lc_size     post_lc_size    tier    placement_time
/file/path/file01   1577573998671406000     17      8192    8236    2       2       0       0       ECS     Sun Mar 28 09:48:19 2021
/file/path/file02   1577574000016210000     18      32768   32868   4       4       0       0       ECS     Sun Mar 28 09:48:19 2021
/file/path/file03   1577574000978268000     19      8192    8236    2       2       0       0       ECS     Sun Mar 28 09:48:19 2021

Sometimes I need to do some data analysis from "placement_time", but this being a string, I have to convert it first to another which is still a string but in a format which allows easy searching or comparisons. Hence use a canned SQL query like below to create a view so that "placement_time" is turned into a better timestamp:

;CREATE VIEW location_report_ptime AS
SELECT *,
    CASE
        WHEN ptime IS NOT NULL THEN
            -- Normalize input like "Sun Mar 9 23:41:59 2025"
            -- Remove weekday (first 4 characters)
            (
                WITH parts AS (
                    SELECT
                        substr(ptime, 5) AS dt -- "Mar 9 23:41:59 2025"
                )
                SELECT
                    printf(
                        '%04d-%02d-%02d %s',
                        CAST(substr(dt, length(dt) - 3, 4) AS INT), -- Year (last 4 chars)
                        CASE substr(dt, 1, 3)                        -- Month abbreviation
                            WHEN 'Jan' THEN 1
                            WHEN 'Feb' THEN 2
                            WHEN 'Mar' THEN 3
                            WHEN 'Apr' THEN 4
                            WHEN 'May' THEN 5
                            WHEN 'Jun' THEN 6
                            WHEN 'Jul' THEN 7
                            WHEN 'Aug' THEN 8
                            WHEN 'Sep' THEN 9
                            WHEN 'Oct' THEN 10
                            WHEN 'Nov' THEN 11
                            WHEN 'Dec' THEN 12
                        END,
                        -- Day part: between month and time
                        CAST(trim(substr(dt, 5, instr(dt, ':') - 8)) AS INT),
                        -- Time part
                        substr(dt, instr(dt, ':') - 2, 8)
                    )
                FROM parts
            )
        ELSE NULL
    END AS iso_date_ptime
FROM location_report;

Which results in another field called "iso_date_ptime" having a date / time string which I can use for things like searching all the files matching the timestamp for a given period of time, ie:

;SELECT path,log_time,ptime,iso_date_ptime FROM location_report_ptime WHERE iso_date_ptime > '2021-01-01' AND iso_date_ptime < '2022-01-01' ORDER BY iso_date_ptime DESC LIMIT 20

Note there may be much simpler and effective ways of achieving the same result, and my approach may be too brute-force.

Fact is, the SQL VIEW above does get created fine and hence I can query the created "location_report_ptime" view fine with pre-compiled lnav 0.13.2, but I can not with my own compiled copy of current code (0.14.0-a2e2380-dirty).

With my compiled version the CREATE VIEW appears to work, but querying the view returns it does not exist, revisiting the CREATE query in SQL mode the result is (info below taken from debug log but lnav UI shows the same):

2025-11-17T07:32:59.612114+01:00 E t0 sql_util.cc:1122 (1) near "parts": syntax error in "CREATE VIEW location_report_ptime AS
SELECT
    *,
    CASE
        WHEN ptime IS NOT NULL THEN -- Normalize input like "Sun Mar 9 23:41:59 2025"
            -- Remove weekd

To Reproduce
As described above.

I understand this is a problem from the underlying SQLite library versions being used (lnav passes the SQL down to the SQLite library and returns whatever it gets from below), and not related to lnav at all, but logging here just in case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions