-
Notifications
You must be signed in to change notification settings - Fork 923
MySQL support for returning auto generated ID on INSERT? #1032
-
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
Beta Was this translation helpful? Give feedback.
All reactions
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
-
你可以在插入时指定ID, 比如UUID 或者 其他形式的自增ID。
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.