{"record":{"id":"3ba5634f19895cb7","repo":"PRQL/prql","slug":"expected-a-table-or-query-found-an-empty-array","errorCode":null,"errorMessage":"expected a table or query, found an empty array `[]`","messagePattern":"expected a table or query, found an empty array `\\[\\]`","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"prqlc/prqlc/src/semantic/resolver/functions.rs","lineNumber":274,"sourceCode":"                        .fold_and_type_check(arg, param, func_name)?\n                        .unwrap_or_else(|a| {\n                            partial_application_position = Some(index);\n                            a\n                        });\n                }\n                log::debug!(\"resolved arg to {}\", arg.kind.as_ref());\n\n                resolved_relations.push((index, arg, is_last));\n            }\n\n            // Then, add relation frames into scope\n            for (index, arg, is_last) in resolved_relations {\n                if partial_application_position.is_none() {\n                    let frame = arg.lineage.as_ref().ok_or_else(|| {\n                        // Provide helpful error for empty arrays/tuples used directly\n                        // (not from functions like std.from_text which set lineage properly)\n                        match &arg.kind {\n                            ExprKind::Array(v) if v.is_empty() => Error::new(Reason::Expected {\n                                who: None,\n                                expected: \"a table or query\".to_string(),\n                                found: \"an empty array `[]`\".to_string(),\n                            })\n                            .with_span(arg.span),\n                            ExprKind::Tuple(v) if v.is_empty() => Error::new(Reason::Expected {\n                                who: None,\n                                expected: \"a table or query\".to_string(),\n                                found: \"an empty tuple `{}`\".to_string(),\n                            })\n                            .with_span(arg.span),\n                            _ => Error::new_bug(4317).with_span(closure.body.span),\n                        }\n                    })?;\n                    if is_last {\n                        self.root_mod.module.insert_frame(frame, NS_THIS);\n                    } else {\n                        self.root_mod.module.insert_frame(frame, NS_THAT);","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/PRQL/prql/blob/e164e249b99485890036eb60f57c37520379b240/prqlc/prqlc/src/semantic/resolver/functions.rs#L256-L292","documentation":"During function resolution, arguments that must be relations (frames with lineage) are checked. A bare empty array `[]` used directly as a pipeline input (e.g. `from []`) has no lineage, so instead of an opaque internal bug the compiler gives this targeted error explaining that empty arrays are not valid tables.","triggerScenarios":"`from []`, `join []`, or passing `[]` to any std function expecting a relation, without going through functions like `std.from_text` that set lineage.","commonSituations":"Building test queries with literal data via wrong means, or forgetting to use `from_text`/`sql` to turn literal data into a table.","solutions":["Remove the empty array and use a real table via `from`","Create data with `std.from_text` (e.g. `from_text format:csv \"a,b\\n1,2\"`) instead of a bare array","If the array is computed, ensure it is non-empty or route it through a function that sets lineage"],"exampleFix":"// before\nfrom []\n// after\nfrom_text format:csv \"a\\n1\"","handlingStrategy":"validation","validationCode":"function validateRelationArg(arg) {\n  if (Array.isArray(arg) && arg.length === 0) {\n    throw new Error(\"empty array is not a table; use from_text or a real table\");\n  }\n}","typeGuard":"function isEmptyArrayLiteral(expr) {\n  return expr && expr.kind === \"array\" && expr.items.length === 0;\n}","tryCatchPattern":"try {\n  compile(query);\n} catch (e) {\n  if (e.message.includes(\"an empty array\")) {\n    console.error(\"Build literal data with std.from_text instead of [].\");\n  } else { throw e; }\n}","preventionTips":["Never pass [] or {} directly to from/join","Use std.from_text for inline data","Verify computed sources are non-empty before compiling"],"tags":["prql","resolver","empty-array"],"backgroundTag":"empty-required-field","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"}