Q046warning

ON CONFLICT DO NOTHING with RETURNING

A one query pairs ON CONFLICT DO NOTHING with RETURNING.

db/queries/example.sql:1:1: warning[Q046]: query "AddAuthor" uses command "one" with ON CONFLICT DO NOTHING and RETURNING; a conflict skips the insert so RETURNING yields no row and the call returns the driver no-rows sentinel (sql.ErrNoRows, or pgx.ErrNoRows for native pgx). Add optional: true to return (row, false, nil), use command "exec"/"execrows", or handle errors.Is with that sentinel.
Printed by sgl from a small PostgreSQL reproduction project.

When it is reported

On a conflict nothing is inserted and RETURNING produces no row, so the generated method returns the driver's no-rows error on that path.

How to fix it

Add optional: true to return (row, false, nil), use exec or execrows, or handle the no-rows error.

See it in an example

In your terminal

$ sgl explain Q046

Look for ConflictDoNothingReturning in Seagull's source to see where it is reported.