{"record":{"id":"489eaf5587ec1884","repo":"PRQL/prql","slug":"std-in-expected-a-pattern-found-found","errorCode":null,"errorMessage":"std.in: expected a pattern, found {found}","messagePattern":"std\\.in: expected a pattern, found (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"prqlc/prqlc/src/semantic/resolver/transforms.rs","lineNumber":336,"sourceCode":"\n                let pattern = match try_restrict_range(pattern) {\n                    Ok((start, end)) => {\n                        let start = restrict_null_literal(start);\n                        let end = restrict_null_literal(end);\n\n                        let start = start.map(|s| new_binop(value.clone(), &[\"std\", \"gte\"], s));\n                        let end = end.map(|e| new_binop(value, &[\"std\", \"lte\"], e));\n\n                        let res = maybe_binop(start, &[\"std\", \"and\"], end);\n                        let res = res.unwrap_or_else(|| {\n                            Expr::new(ExprKind::Literal(Literal::Boolean(true)))\n                        });\n                        return Ok(res);\n                    }\n                    Err(expr) => expr,\n                };\n\n                return Err(Error::new(Reason::Expected {\n                    who: Some(\"std.in\".to_string()),\n                    expected: \"a pattern\".to_string(),\n                    found: write_pl(pattern.clone()),\n                })\n                .with_span(pattern.span));\n            }\n\n            \"tuple_reduce\" => {\n                // yes, this is not a transform, but this is the most appropriate place for it\n\n                let [init, func, list] = unpack::<3>(func.args);\n                let list_items = list.kind.into_tuple().unwrap();\n                let num_items = list_items.len();\n                let mut list_iter = list_items.into_iter();\n\n                let mut res = init.clone();\n\n                if let ExprKind::Literal(Literal::String(init_val)) = &init.kind {","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/PRQL/prql/blob/e164e249b99485890036eb60f57c37520379b240/prqlc/prqlc/src/semantic/resolver/transforms.rs#L318-L354","documentation":"The `std.in` operator tests membership in a list of values, and its argument must be a list literal (pattern) such as `[1, 2, 3]` or a range. This error is thrown when the argument to `in` cannot be resolved into a valid pattern — for example a bare scalar, an arbitrary expression, or a malformed list.","triggerScenarios":"Writing `x | in (foo + 1)` or `filter std.in some_expr` where the second argument fails to fold into a list/range pattern; also passing a single non-list value or a variable that is not a list literal.","commonSituations":"Using SQL habits like `col IN (SELECT ...)` expecting subquery support in PRQL `in`; passing a column or function call instead of a literal list; forgetting brackets around the value list.","solutions":["Pass a literal list: `filter code in ['A', 'B', 'C']`.","Use a range pattern for intervals: `filter age in 18..65`.","Replace a subquery membership test with a join or `filter` over a `from` pipeline.","Check that the argument isn't a typo'd scalar or unparenthesized expression."],"exampleFix":"// before\nfrom t | filter code in codes_table\n// after\nfrom t | filter code in ['A', 'B', 'C']","handlingStrategy":"validation","validationCode":"// Validate std.in arguments are list literals or ranges\nfunction validateInArgs(prql) {\n  const re = /in\\s+([^\\s|)]+)\\s*([|)]|$)/g;\n  let m;\n  while ((m = re.exec(prql))) {\n    const arg = m[1].trim();\n    if (!arg.startsWith('[') && !/^(\\d+\\.\\.|-?\\d+\\.\\.\\d+)/.test(arg)) {\n      throw new Error(`std.in expects a list literal or range, found: ${arg}`);\n    }\n  }\n}","typeGuard":"function isValidInPattern(arg) {\n  return Array.isArray(arg) || (arg != null && typeof arg === 'object' && 'start' in arg && 'end' in arg);\n}","tryCatchPattern":"try {\n  const sql = prqlc.compile(query);\n} catch (e) {\n  if (e.message.includes('std.in: expected a pattern')) {\n    // suggest in [a, b, c] or a range; rewrite subquery membership as a join\n  } else throw e;\n}","preventionTips":["Always use bracketed literal lists with `in`: `in ['a','b']`.","Use ranges for interval checks: `in 1..10`.","Do not pass subqueries, columns, or bare expressions to `in`; use a join instead."],"tags":["prql","std-in","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"e164e249b99485890036eb60f57c37520379b240","analyzedAt":"2026-09-09T12:18:38.727Z","contentChangedAt":"2026-09-09T12:18:38.727Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}