Skip to content

Postgres: Incorrect ending line reported in Span for multi-line query #1858

Closed

Description

@agis

Using 0.56.0 and the following code:

use sqlparser::dialect::PostgreSqlDialect;
use sqlparser::parser::Parser as Parser;

fn f()
    let dialect = PostgreSqlDialect {};
    let sql = r#"-- foo
ALTER TABLE users
  ADD COLUMN foo
  varchar; -- hi there

-- bar
-- baz
ALTER TABLE users ADD COLUMN bar varchar; SELECT 1;"#;

    let ast = Parser::parse_sql(&dialect, sql).unwrap();

    for stmt in ast {
        let s = stmt.span();
        println!("stmt: {} | start: {} | end: {}", stmt, s.start, s.end);
    }
}

The output I get is:

stmt: ALTER TABLE users ADD COLUMN foo VARCHAR | start:  at Line: 2, Column: 13 | end:  at Line: 3, Column: 17
stmt: ALTER TABLE users ADD COLUMN bar VARCHAR | start:  at Line: 8, Column: 13 | end:  at Line: 8, Column: 33
stmt: SELECT 1 | start:  at Line: 8, Column: 43 | end:  at Line: 8, Column: 51

Everything seems correct to me, except of the ending line of the first query, which I expected it to be 4 instead of 3.

Activity

  1. changed the title [-]Incorrect `Spanned.end` value in multi-line query[/-] [+]Incorrect `Span.end` value in multi-line query[/+] on May 23, 2025
  2. changed the title [-]Incorrect `Span.end` value in multi-line query[/-] [+]Postgres: Incorrect ending line reported in `Span` for multi-line query[/+] on May 29, 2025
  3. added a commit that references this issue on Aug 9, 2025
    fdf2545
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions