query.sql:57:96: edited query syntax is invalid: syntax error at or near "ext"
If I replace the @now with sqlc.arg(now) though it works. I also get errors if I replace sqlc.arg(timezone) with @timezone
Relevant log output
No response
Database schema
CREATE TABLE wordvault_cards(
user_id BIGINT NOT NULL,
lexicon_name TEXT NOT NULL,
alphagram TEXT NOT NULL,
next_scheduled TIMESTAMPTZ NOT NULL,
fsrs_card JSONB NOT NULL DEFAULT '{}',
review_log JSONB NOT NULL DEFAULT '[]',
UNIQUE(user_id, lexicon_name, alphagram));
SQL queries
-- name: GetDailyProgress :one
SELECT
-- Count of new cards studied today
SUM(CASE
WHEN jsonb_array_length(review_log) = 1
THEN 1
ELSE 0
END) AS new_cards,
-- Count of reviewed cards studied today
SUM(CASE
WHEN jsonb_array_length(review_log) > 1
THEN 1
ELSE 0
END) AS reviewed_cards,
-- Rating breakdown for new cards
COUNT(*) FILTER (
WHERE jsonb_array_length(review_log) = 1
AND (review_log->0->>'Rating')::int = 1
) AS new_rating_1,
COUNT(*) FILTER (
WHERE jsonb_array_length(review_log) = 1
AND (review_log->0->>'Rating')::int = 2
) AS new_rating_2,
COUNT(*) FILTER (
WHERE jsonb_array_length(review_log) = 1
AND (review_log->0->>'Rating')::int = 3
) AS new_rating_3,
COUNT(*) FILTER (
WHERE jsonb_array_length(review_log) = 1
AND (review_log->0->>'Rating')::int = 4
) AS new_rating_4,
-- Rating breakdown for reviewed cards
COUNT(*) FILTER (
WHERE jsonb_array_length(review_log) > 1
AND (review_log->-1->>'Rating')::int = 1
) AS reviewed_rating_1,
COUNT(*) FILTER (
WHERE jsonb_array_length(review_log) > 1
AND (review_log->-1->>'Rating')::int = 2
) AS reviewed_rating_2,
COUNT(*) FILTER (
WHERE jsonb_array_length(review_log) > 1
AND (review_log->-1->>'Rating')::int = 3
) AS reviewed_rating_3,
COUNT(*) FILTER (
WHERE jsonb_array_length(review_log) > 1
AND (review_log->-1->>'Rating')::int = 4
) AS reviewed_rating_4
FROM
wordvault_cards
WHERE
user_id = @user_id
AND ((fsrs_card->>'LastReview')::timestamp AT TIME ZONE 'UTC' AT TIME ZONE sqlc.arg(timezone)::text)::date = (@now::timestamptz AT TIME ZONE sqlc.arg(timezone)::text)::date;
Version
1.27.0
What happened?
query.sql:57:96: edited query syntax is invalid: syntax error at or near "ext"
If I replace the
@now
withsqlc.arg(now)
though it works. I also get errors if I replacesqlc.arg(timezone)
with@timezone
Relevant log output
No response
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/4ee8022578aa223609e351bfbc131f097328ba65d923d1e397ba33cf62d189aa
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go