SQLite Forum

INSERT with RETURNING causes duplicate rows
Login
## Problem
Using the php SQLite3 driver (3.35.5), when issuing this command:

```sql 
CREATE TABLE profile
(
    profile_id INTEGER NOT NULL PRIMARY KEY autoincrement,
    name VARCHAR(64),
    email VARCHAR(255),
    age INT NOT NULL DEFAULT 0,
    created VARCHAR(20) NOT NULL DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO "profile" ("age", "email", "name") 
    VALUES (47, 'a@gmail.com', 'Adam Fry') 
        RETURNING "profile_id", "email";
```

I get duplicate rows. So if the autoinc seq is at 10, I get a row with 11 and 12 with the same data. If I remove the RETURNING clause, only one record is inserted and the sequence is only incremented once. I tested this to ensure a second insert without returning gave me the next sequence value without gaps.

The example is soo simple, I can't really see what I am doing wrong. I have tracked my code and I am certain I do not issue TWO insert statements.

Thank you,
achernow