Repository: taozhi8833998/node-sql-parser

Issue:
insert RETURNING is broken in Sqlite with omitted column names
**Describe the bug**
`RETURNING` is not working in SQLite (and possibly others).

**Database Engine**
Sqlite

**To Reproduce**
- sql:
    - `INSERT INTO users VALUES (2, "example", "example@example.com") RETURNING *;`
    - `INSERT INTO users VALUES (2, "example", "example@example.com") RETURNING email;`
    - `INSERT INTO users VALUES (2, "example", "example@example.com") RETURNING id,email;`
- node-sql-parser version: 5.3.13
- node version: 22.19.0

**Expected behavior**
I expected this to be successfully parsed, with the `returning` property populated in the AST.

**Additional context**
I get the following error:
```
[SyntaxError]: Expected "#", ",", "--", "/*", ";", "ON", [ \t\n\r], or end of input but "R" found.
```

Discussion:
@electrovir: I just discovered that this is only broken if the column names are omitted. The following _does_ work:
```
INSERT INTO users (id, name, email) VALUES (2, "example", "example@example.com") RETURNING id,email;
```

`returning`, however, is supported in Sqlite in both situations (column names listed and column names omitted).

Solution patch:
diff --git a/pegjs/sqlite.pegjs b/pegjs/sqlite.pegjs
index 7fc239d..6026ffc 100644
--- a/pegjs/sqlite.pegjs
+++ b/pegjs/sqlite.pegjs
@@ -1891,7 +1891,8 @@ insert_no_columns_stmt
     t:table_name  __
     p:insert_partition? __
     v:insert_value_clause __
-    odp: on_duplicate_update_stmt? {
+    odp: on_duplicate_update_stmt? __
+    r:returning_stmt? {
       if (t) {
         tableList.add(`insert::${t.db}::${t.table}`)
         columnList.add(`insert::${t.table}::(.*)`);
@@ -1909,6 +1910,7 @@ insert_no_columns_stmt
           partition: p,
           prefix,
           on_duplicate_update: odp,
+          returning: r,
         }
       };
     }



Test patch:
diff --git a/test/sqlite.spec.js b/test/sqlite.spec.js
index e46d8fe..5f8c11c 100644
--- a/test/sqlite.spec.js
+++ b/test/sqlite.spec.js
@@ -235,12 +235,16 @@ describe('sqlite', () => {
   })
 
   it('should support INSERT ... RETURNING *', () => {
-    const sql = `INSERT INTO users (email) VALUES (?) RETURNING *`
+    let sql = `INSERT INTO users (email) VALUES (?) RETURNING *`
     expect(getParsedSql(sql)).to.be.equal(`INSERT INTO "users" (email) VALUES (?) RETURNING *`)
+    sql = `INSERT INTO users VALUES (2, "example", "example@example.com") RETURNING *;`
+    expect(getParsedSql(sql)).to.be.equal(`INSERT INTO "users" VALUES (2,"example","example@example.com") RETURNING *`)
   })
   it('should support INSERT ... RETURNING specific columns', () => {
-    const sql = `INSERT INTO users (email) VALUES (?) RETURNING id, email as email_address`
+    let sql = `INSERT INTO users (email) VALUES (?) RETURNING id, email as email_address`
     expect(getParsedSql(sql)).to.be.equal(`INSERT INTO "users" (email) VALUES (?) RETURNING "id", "email" AS "email_address"`)
+    sql = `INSERT INTO users VALUES (2, "example", "example@example.com") RETURNING id, email;`
+    expect(getParsedSql(sql)).to.be.equal(`INSERT INTO "users" VALUES (2,"example","example@example.com") RETURNING "id", "email"`)
   })
   it('should support UPDATE ... RETURNING *', () => {
     const sql = `UPDATE users SET email = ? RETURNING *`