You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to generate code for an UPDATE query using sqlc, I encountered two different errors depending on the syntax used:
Error 1 :
When using $1 and $2 as positional placeholders in the query:
UPDATEproducts.productsSET name = coalesce(sqlc.narg(name), name),
updated_at = now()
WHERE id = $1AND merchant_id = $2
RETURNING *;
The error reported by sqlc is:
internal/data/queries/product.sql:42:1: star expansion failed for query
Error 2 :
When using sqlc.arg() for named parameters:
-- name: UpdateProduct :one
UPDATE products.products
SET name = coalesce(sqlc.narg(name), name),
updated_at = now()
WHERE id = sqlc.arg(id)
AND merchant_id = sqlc.arg(merchant_id)
RETURNING *;
The error reported by sqlc is:
internal/data/queries/product.sql:46:12: schema "sqlc" does not exist
Both queries execute successfully when run directly in the database, indicating that the issue lies with sqlc's parsing or code generation.
Relevant log output
error1: internal/data/queries/product.sql:42:1: star expansion failed for query
error2: internal/data/queries/product.sql:46:12: schema "sqlc" does not exist
Database schema
CREATESCHEMAIF NOT EXISTS merchant;
SET SEARCH_PATH TO merchant, products;
CREATEFUNCTIONuuidv7_sub_ms() RETURNS uuid
AS
$$
select encode(
substring(int8send(floor(t_ms)::int8) from3) ||
int2send((7<<12)::int2 | ((t_ms - floor(t_ms)) *4096)::int2) ||substring(uuid_send(gen_random_uuid()) from9 for 8)
, 'hex')::uuid
from (select extract(epoch from clock_timestamp()) *1000as t_ms) s
$$ LANGUAGE sql volatile;
CREATETABLEmerchant.stock_alerts
(
id UUID DEFAULT uuidv7_sub_ms() PRIMARY KEY,
product_id UUID NOT NULL,
merchant_id UUID NOT NULL,
threshold INTNOT NULLCHECK (threshold >0),
created_at TIMESTAMPTZNOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZNOT NULL DEFAULT NOW(),
UNIQUE (product_id, merchant_id)
);
CREATETABLEproducts.products
(
id UUID DEFAULT uuidv7_sub_ms(),
merchant_id UUID NOT NULL,
name VARCHAR(255) NOT NULL,
description TEXT,
price NUMERIC(15, 2) CHECK (price >=0),
status SMALLINTNOT NULL DEFAULT 1,
current_audit_id UUID,
category_id int8 NOT NULL,
created_at TIMESTAMPTZNOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZNOT NULL DEFAULT NOW(),
deleted_at TIMESTAMPTZ,
PRIMARY KEY (merchant_id, id)
);
SQL queries
-- name: UpdateProduct :oneUPDATEproducts.productsSET name = coalesce(sqlc.narg(name), name),
updated_at = now()
WHERE id =sqlc.arg(id)
AND merchant_id =sqlc.arg(merchant_id)
RETURNING *;
-- name: UpdateProduct2 :oneUPDATEproducts.productsSET name = $3,
updated_at = now()
WHERE id = $1AND merchant_id = $2
RETURNING *;
Version
1.28.0
What happened?
When attempting to generate code for an UPDATE query using sqlc, I encountered two different errors depending on the syntax used:
When using $1 and $2 as positional placeholders in the query:
The error reported by sqlc is:
When using sqlc.arg() for named parameters:
The error reported by sqlc is:
Both queries execute successfully when run directly in the database, indicating that the issue lies with sqlc's parsing or code generation.
Relevant log output
Database schema
SQL queries
Configuration
Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: