Skip to content

Named parameters for MySQL inserts / updates #3038

Answered by kyleconroy
SebastienMelki asked this question in Q&A
Discussion options

You must be logged in to vote

The named parameter syntax you're using is not native to MySQL. It's an extension added by sqlx. To use named parameters with sqlc, you need to use the sqlc.arg function, like so:

/* name: InsertPurchaseGuid :exec */
INSERT INTO purchase_guids (
  external_id,
  guid,
  created_at,
  updated_at,
  partner_id,
  payment_method_id
) VALUES (
  sqlc.arg('external_id'),
  sqlc.arg('guid'),
  sqlc.arg('created_at'),
  sqlc.arg('updated_at'),
  sqlc.arg('partner_id'),
  sqlc.arg('payment_method_id')
 );

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@SebastienMelki
Comment options

@kyleconroy
Comment options

@SebastienMelki
Comment options

Answer selected by kyleconroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3037 on December 05, 2023 16:57.