Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MySQL support for returning auto generated ID on INSERT? #1032

Discussion options

Is it possible to support to retrieve the last ID upon INSERT? I know MySQL supports SELECT LAST_INSERT_ID() but I was wondering the INSERT generated by sqlc can at least return the auto genereted ID

You must be logged in to vote

For Postgres you can add RETURN id to your query and use :one. For MySQL, use :execresult which makes your query return a sql.Result, which has a LastInsertId() (int64, error) method.

Replies: 2 comments

Comment options

你可以在插入时指定ID, 比如UUID 或者 其他形式的自增ID。

You must be logged in to vote
0 replies
Comment options

For Postgres you can add RETURN id to your query and use :one. For MySQL, use :execresult which makes your query return a sql.Result, which has a LastInsertId() (int64, error) method.

You must be logged in to vote
0 replies
Answer selected by kyleconroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /