{"record":{"id":"0b0c05d7bcc56a95","repo":"PRQL/prql","slug":"expected-a-pipeline-that-resolves-to-a-table-foun","errorCode":null,"errorMessage":"expected a pipeline that resolves to a table, found `{found_str}`","messagePattern":"expected a pipeline that resolves to a table, found `(.+?)`","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"prqlc/prqlc/src/semantic/lowering.rs","lineNumber":431,"sourceCode":"                log::debug!(\"lowering literal relation table, columns = {columns:?}\");\n                let relation = rq::Relation {\n                    kind: rq::RelationKind::Literal(lit),\n                    columns,\n                };\n\n                self.table_buffer.push(TableDecl {\n                    id: tid,\n                    name: None,\n                    relation,\n                });\n\n                // return an instance of this new table\n                self.create_a_table_instance(id, None, tid)\n            }\n\n            _ => {\n                let found_str = write_pl(expr.clone());\n                let mut error = Error::new(Reason::Expected {\n                    who: None,\n                    expected: \"a pipeline that resolves to a table\".to_string(),\n                    found: format!(\"`{}`\", found_str),\n                });\n\n                // Provide better hints for common mistakes\n                if found_str.starts_with(\"internal std.sub\") {\n                    // This is likely a negative number or expression that should be wrapped in parentheses\n                    error = error.push_hint(\n                        \"wrap negative numbers in parentheses, e.g. `sort (-column_name)`\",\n                    );\n                } else {\n                    error = error.push_hint(\"`from` statement might be missing?\");\n                }\n\n                return Err(error.with_span(expr.span));\n            }\n        })","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/PRQL/prql/blob/e164e249b99485890036eb60f57c37520379b240/prqlc/prqlc/src/semantic/lowering.rs#L413-L449","documentation":"During lowering (semantic IR to SQL IR), PRQL expects the function-call argument or pipeline fed to a relational context (e.g. `from x | ...` used as a value) to resolve to a table. If the expression instead lowers to a non-table value (a scalar, column, or unlowered expression), the compiler throws this error and then tries to attach hints for common mistakes.","triggerScenarios":"Passing a non-table expression where a relation is required, e.g. `select (from employees)` (subquery in scalar position), `join`ing against a scalar, or feeding a column expression where a pipeline resolving to a table is expected.","commonSituations":"Writing an inline subquery without the std-style pattern, mistyping a table name so it resolves to something else, or using a scalar function result as a pipeline source.","solutions":["Ensure the expression is a full pipeline that ends in a table (e.g. `from employees`) rather than a scalar or column expression","If you intended a scalar comparison, move the pipeline out of the scalar context or use `first`/aggregate to reduce it to a value","Check the found expression in the error message; correct typos or missing `from` clauses","See the attached hint (the compiler adds hints for common mistakes such as missing `from`)"],"exampleFix":"// before\nselect (employees)\n// after\nfrom employees | select name","handlingStrategy":"type-guard","validationCode":"// Ensure the expression is a pipeline starting with from\n// e.g. reject scalars/strings passed as sources\nif (!query.trim().startsWith(\"from \")) {\n  throw new Error(\"pipeline must start with `from <table>`\");\n}","typeGuard":"function isTablePipeline(expr) {\n  return typeof expr === \"string\" && /(^|\\|)\\s*from\\s+\\w+/.test(expr);\n}","tryCatchPattern":"try {\n  compile(query);\n} catch (e) {\n  if (e.message.includes(\"a pipeline that resolves to a table\")) {\n    console.error(\"Add a `from <table>` clause; subqueries need a full pipeline:\", e.message);\n  } else { throw e; }\n}","preventionTips":["Always start pipelines with `from <table>`","Do not nest `from` pipelines in scalar contexts like select","Use first/aggregate to reduce relations to values when a scalar is needed"],"tags":["prql","lowering","type-error"],"backgroundTag":"type-mismatch","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"}