Skip to content

Fix README quick example: use $batch.* row-set expansion#257

Draft
tjgreen42 wants to merge 1 commit into
mainfrom
tjgreen42/fix-readme-batch-example
Draft

Fix README quick example: use $batch.* row-set expansion#257
tjgreen42 wants to merge 1 commit into
mainfrom
tjgreen42/fix-readme-batch-example

Conversation

@tjgreen42

Copy link
Copy Markdown
Contributor

Problem

The Quick Example in the README failed at runtime:

SQL execution failed: error returned from database: op ANY/ALL (array) requires array on right side

A bare $var capture substitutes only the first column of the first row as a scalar. The capture batch holds {"rows":[{"id":1},{"id":2},...]}, so $batch expanded to 1 and the UPDATE became ... WHERE id = ANY(1), which is invalid because 1 is not an array.

Fix

Use the $batch.* row-set expansion, which expands the captured result into an inline (VALUES ...) AS batch(id), referenced as a subquery:

~> 'UPDATE documents SET processed = true WHERE id IN (SELECT id FROM $batch.*)'

Verification

Ran the corrected example against a local pg_durable instance: the instance reached completed and the expected rows were updated to processed = true.

The Quick Example used `id = ANY($batch)`, but a bare $var substitutes
only the first column of the first captured row as a scalar, so the
generated SQL was `id = ANY(1)` and failed with "op ANY/ALL (array)
requires array on right side".

Use the $batch.* row-set expansion instead, referencing the captured
result as a subquery: `id IN (SELECT id FROM $batch.*)`.

@pinodeca pinodeca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants