Skip to content

[Bug]: OFFSET does not work unless I add -- at the end #273

@GiteshDohare

Description

@GiteshDohare

Describe the bug

When I run a query using OFFSET, the app ignores the OFFSET part and gives me the wrong result.
However, if I add a SQL comment (--) to the very end of the query, it suddenly works perfectly.
Tested this in Postgres
In example, I am trying to find 2nd highest salary from employees table.

Image

To Reproduce

To Reproduce, Run this query (without a comment):

SELECT DISTINCT salary 
FROM employees 
WHERE salary IS NOT NULL
ORDER BY salary DESC
LIMIT 1 OFFSET 1;

Result: It returns the highest salary instead of the 2nd highest. It completely ignores OFFSET 1.


Now run the same query but add -- at the end:

SELECT DISTINCT salary 
FROM employees 
WHERE salary IS NOT NULL
ORDER BY salary DESC
LIMIT 1 OFFSET 1;  --

Result: It works perfectly and returns the 2nd highest salary.


Query to Create Table with Exact Data I have

CREATE TABLE "employees" (
  "employee_id" SERIAL NOT NULL,
  "first_name" character varying NOT NULL,
  "last_name" character varying NOT NULL,
  "email" character varying,
  "hire_date" date DEFAULT CURRENT_DATE,
  "salary" numeric,
  "is_active" boolean DEFAULT true,
  PRIMARY KEY ("employee_id")
);

CREATE UNIQUE INDEX "employees_email_key" ON "employees" ("email");

INSERT INTO employees (first_name, last_name, email, hire_date, salary, is_active)
VALUES 
    ('John', 'Doe', 'john.doe@example.com', '2023-01-15', 65000.00, TRUE),
    ('Jane', 'Smith', 'jane.smith@example.com', '2022-11-10', 75000.00, TRUE),
    ('Bob', 'Johnson', 'bob.johnson@example.com', '2024-03-01', 55000.00, FALSE),
    ('Alice', 'Williams', 'alice.williams@example.com', '2021-06-22', 90000.00, TRUE);

OS Version

Ubuntu 24.04

Tabularis Version

v0.12.0

Relevant Log Output

[2026-06-02 21:34:31.312] [INFO] Connection test successful for database: test-db (target: tabularis_lib::commands)
[2026-06-02 21:34:31.313] [INFO] Health check: registering connection 235be7ab-2f0f-44fa-a7af-d7c9a05b74ca (target: tabularis_lib::health_check)
[2026-06-02 21:34:31.314] [INFO] Fetching schemas for connection: 235be7ab-2f0f-44fa-a7af-d7c9a05b74ca (target: tabularis_lib::commands)
[2026-06-02 21:34:31.314] [INFO] Creating new PostgreSQL connection pool for: postgres@Some("localhost") (key: postgres:conn:235be7ab-2f0f-44fa-a7af-d7c9a05b74ca:test-db) (target: tabularis_lib::pool_manager)
[2026-06-02 21:34:31.314] [INFO] PostgreSQL connection pool created successfully for: test-db (key: postgres:conn:235be7ab-2f0f-44fa-a7af-d7c9a05b74ca:test-db) (target: tabularis_lib::pool_manager)
[2026-06-02 21:34:31.334] [INFO] Fetching tables for connection: 235be7ab-2f0f-44fa-a7af-d7c9a05b74ca (target: tabularis_lib::commands)
[2026-06-02 21:34:31.334] [INFO] Fetching views for connection: 235be7ab-2f0f-44fa-a7af-d7c9a05b74ca (target: tabularis_lib::commands)
[2026-06-02 21:34:31.334] [INFO] Fetching routines for connection: 235be7ab-2f0f-44fa-a7af-d7c9a05b74ca (target: tabularis_lib::commands)
[2026-06-02 21:34:31.334] [INFO] Fetching triggers for connection: 235be7ab-2f0f-44fa-a7af-d7c9a05b74ca (target: tabularis_lib::commands)
[2026-06-02 21:34:31.337] [INFO] Retrieved 1 tables from test-db (target: tabularis_lib::commands)
[2026-06-02 21:34:31.341] [INFO] Retrieved 0 views from test-db (target: tabularis_lib::commands)
[2026-06-02 21:34:31.342] [INFO] Retrieved 0 triggers (target: tabularis_lib::commands)
[2026-06-02 21:34:44.083] [INFO] Executing query on connection: 235be7ab-2f0f-44fa-a7af-d7c9a05b74ca | Query: SELECT DISTINCT salary 
FROM employees 
WHERE salary IS NOT NULL
ORDER BY salary DESC
LIMIT 1 OFFSET 1 (target: tabularis_lib::commands)
[2026-06-02 21:34:44.085] [INFO] Query executed successfully, returned 1 rows (target: tabularis_lib::commands)
[2026-06-02 21:36:28.905] [INFO] Executing query on connection: 235be7ab-2f0f-44fa-a7af-d7c9a05b74ca | Query: SELECT DISTINCT salary 
FROM employees 
WHERE salary IS NOT NULL
ORDER BY salary DESC
LIMIT 1 OFFSET 1 -- (target: tabularis_lib::commands)
[2026-06-02 21:36:28.907] [INFO] Query executed successfully, returned 1 rows (target: tabularis_lib::commands)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions