Skip to content

[BUG] VSCE: Incorrect LIMIT placement when previewing analyses queries #1377

@sophieml

Description

@sophieml

Describe the bug
When previewing analyses, the LIMIT portion of dbt show is placed on the last line of the query. If the last line is an inline comment, the limit is appended to that comment and therefore not run as part of the executed SQL. Anecdotally, this causes the extension to become unstable when attempting to preview a large volume of rows.

When previewing models, the query is wrapped in select * from (...) limit 1000;, which avoids this issue.

What version of dbt Fusion is this bug in? (find out by running dbt --version)
LSP and CLI preview 120

Is this a discrepancy between the dbt Fusion Engine and dbt Core? Check one.

  • YES
  • NO

To Reproduce

-- analyses/example.sql
SELECT 1
-- comment
  1. Preview above analysis using VSCE
  2. Observe placement of limit in query to DWH:
-- logs/query_log.sql
-- created_at: 2026-02-27T23:51:54.958961500+00:00
-- finished_at: 2026-02-27T23:51:55.839004700+00:00
-- elapsed: 880ms
-- outcome: success
-- dialect: snowflake
-- node_id: not available
-- query_id: not available
-- desc: dbt run query
SELECT 1
-- comment limit 1000;

Expected behavior
LIMIT is added to the executed SQL such that it always executes as expected.

Screenshots

Operating System and CPU Type (please complete the following information):

  • Windows x86

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