{"record":{"id":"cfad4cd20b0b4823","repo":"PRQL/prql","slug":"take-expected-int-or-range-found-found","errorCode":null,"errorMessage":"`take`: expected int or range, found {found}","messagePattern":"`take`: expected int or range, found (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"prqlc/prqlc/src/semantic/resolver/transforms.rs","lineNumber":83,"sourceCode":"                        ColumnSort { direction, column }\n                    })\n                    .collect();\n\n                (TransformKind::Sort { by }, tbl)\n            }\n            \"take\" => {\n                let [expr, tbl] = unpack::<2>(func.args);\n\n                let range = if let ExprKind::Literal(Literal::Integer(n)) = expr.kind {\n                    range_from_ints(None, Some(n))\n                } else {\n                    match try_restrict_range(expr) {\n                        Ok((start, end)) => Range {\n                            start: restrict_null_literal(start).map(Box::new),\n                            end: restrict_null_literal(end).map(Box::new),\n                        },\n                        Err(expr) => {\n                            return Err(Error::new(Reason::Expected {\n                                who: Some(\"`take`\".to_string()),\n                                expected: \"int or range\".to_string(),\n                                found: write_pl(expr.clone()),\n                            })\n                            // Possibly this should refer to the item after the `take` where\n                            // one exists?\n                            .with_span(expr.span));\n                        }\n                    }\n                };\n\n                (TransformKind::Take { range }, tbl)\n            }\n            \"join\" => {\n                let [side, with, filter, tbl] = unpack::<4>(func.args);\n\n                let side = {\n                    let span = side.span;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/PRQL/prql/blob/e164e249b99485890036eb60f57c37520379b240/prqlc/prqlc/src/semantic/resolver/transforms.rs#L65-L101","documentation":"The `take` transform's argument is resolved and must be either an integer literal or a range expression. `try_restrict_range` attempts to normalize the argument into a Range; if the expression is neither (e.g. a string, list, tuple, or unresolved identifier), this error is thrown naming `take` as the context.","triggerScenarios":"`take \"10\"`, `take [1,2]`, `take x` where `x` is not an int/range at resolve time, or `take` applied to a named argument.","commonSituations":"Passing user-supplied values of the wrong type, quoting the number, or passing a tuple of counts instead of a range `a..b`.","solutions":["Pass a plain int (`take 10`) or a range (`take 5..15`)","Convert the value to an int before passing it to take","Remove quotes/braces around the argument"],"exampleFix":"// before\ntake \"10\"\n// after\ntake 10","handlingStrategy":"validation","validationCode":"function validateTakeArg(v) {\n  const isInt = (x) => typeof x === \"number\" && Number.isInteger(x) && x >= 0;\n  const ok = isInt(v) || (Array.isArray(v) && v.length === 2 && v.every(isInt) && v[0] <= v[1]);\n  if (!ok) throw new Error(\"take requires an int or range like a..b\");\n}","typeGuard":"function isIntOrRange(v) {\n  return Number.isInteger(v) ||\n    (Array.isArray(v) && v.length === 2 && v.every(n => Number.isInteger(n)));\n}","tryCatchPattern":"try {\n  compile(query);\n} catch (e) {\n  if (e.message.includes(\"`take`\") && e.message.includes(\"int or range\")) {\n    console.error(\"Pass take 10 or take 5..15 — no strings, tuples, or untyped variables.\");\n  } else { throw e; }\n}","preventionTips":["Pass unquoted integers to take","Use range syntax a..b for windows, not lists/tuples","Coerce user input to int before interpolation into the query"],"tags":["prql","take","argument-type"],"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"}