Repository navigation
|
I'm trying to fetch the autoincremented primary key from an INSERT statement like so: SET new_id = INSERT INTO shelves (name, description, owner_id)
VALUES (:name, :description, :session_user)
RETURNING id;The INSERT syntax is fine but I get the following error from sqlpage: The idea is to capture the ID so I can redirect to a "shelf" page. What's the right way to do this, or is this completely the wrong pattern? |
Answered by
lovasoa
Dec 4, 2026
Replies: 1 comment 1 reply
|
Hi ! Most databases have a builtin function that does what you want. In sqlite it's drop table if exists shelves;
create table shelves
(id integer primary key autoincrement,
name, description, owner_id);
INSERT INTO shelves
(name, description, owner_id)
VALUES
(:name, :description, :session_user);
SET new_id = last_insert_rowid();
select 'debug' as component, $new_id as new_id;
That said, I don't like the error message you are seeing, I'll look into it ! |
1 reply
Answer selected by
keisisqrl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Hi !
Most databases have a builtin function that does what you want. In sqlite it's
last_insert_rowid. SQLPage runs all statements from a file on the same connection, sequentially, so it's safe to use even under high concurrency.That said, I don't like the error message you are seeing, I'll look into it !