{"record":{"id":"f6ab2effeb73085f","repo":"dbt-labs/dbt-core","slug":"the-statement-result-named-name-has-already","errorCode":null,"errorMessage":"The 'statement' result named '{name}' has already been loaded into a variable","messagePattern":"The 'statement' result named '(.+?)' has already been loaded into a variable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/load_store.rs","lineNumber":113,"sourceCode":"\n    /// https://github.com/dbt-labs/dbt-core/blob/34bb3f94dde716a3f9c36481d2ead85c211075dd/core/dbt/context/providers.py#L1022\n    pub fn load_result(\n        &self,\n    ) -> impl Fn(&[Value]) -> Result<Value, minijinja::Error> + Clone + use<> {\n        let store = self.clone();\n        move |args: &[Value]| {\n            // name: str,\n            let iter = ArgsIter::new(\"load_result\", &[\"name\"], args);\n            let name: String = iter.next_arg::<&str>()?.to_string();\n            iter.finish()?;\n\n            let mut results = store.results.lock().unwrap();\n\n            if let Some(value) = results.get_mut(&name) {\n                if name == \"main\" {\n                    Ok(value.clone())\n                } else if *value == none_value() {\n                    Err(minijinja::Error::new(\n                        minijinja::ErrorKind::MacroResultAlreadyLoadedError,\n                        format!(\n                            \"The 'statement' result named '{name}' has already been loaded into a variable\"\n                        ),\n                    ))\n                } else {\n                    let result = value.clone();\n                    *value = none_value();\n                    Ok(result)\n                }\n            } else {\n                Ok(none_value())\n            }\n        }\n    }\n\n    /// https://github.com/dbt-labs/dbt-core/blob/34bb3f94dde716a3f9c36481d2ead85c211075dd/core/dbt/context/providers.py#L1043\n    pub fn store_raw_result(","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/load_store.rs#L95-L131","documentation":"store_result saves the result of a {% set result %}/{% statement %} block into a shared result store keyed by name. If the stored value has already been consumed (it equals the 'none_value()' placeholder), loading it again is refused with MacroResultAlreadyLoadedError: each named statement result can be read into a variable only once. The name 'main' is exempt and can be re-read.","triggerScenarios":"A macro or template loads the same named statement result twice, e.g. calling load_result('foo') twice after a {% set foo %}...{% endset %} statement, or storing under a name that was already loaded (store_result called from CompileNodeCtx/ResolveCtx pipelines with duplicate result names).","commonSituations":"Reusing a result variable across two Jinja calls in one node's compilation; copy-pasted macros that both do load_result('stmt'); running a node whose compile and resolve contexts both store/load the same statement name; upgrading dbt where previously tolerated double-loads now error.","solutions":["Rename each statement/set-result block so every result has a unique name and is loaded only once.","Assign the loaded value to a variable once and reuse the variable instead of calling load_result again.","Use the reserved name 'main' only when re-reading is intended, since it bypasses the already-loaded check.","Refactor shared macros to pass the result as an argument rather than re-fetching it from the store."],"exampleFix":"// before\n{% do load_result('stmt') %}\n{% do load_result('stmt') %}\n// after\n{% set res = load_result('stmt') %}\n{% do use(res) %} {# reuse the variable, do not re-load #}","handlingStrategy":"try-catch","validationCode":"{% set existing = context.get('loaded_results', {}).get('stmt') %}\n{% if existing is none %}\n  {% set res = load_result('stmt') %}\n{% else %}\n  {% set res = existing %}\n{% endif %}","typeGuard":null,"tryCatchPattern":"match store.store_result(name, value) {\n    Ok(v) => v,\n    Err(e) if e.kind() == minijinja::ErrorKind::MacroResultAlreadyLoadedError => reuse_previously_loaded(name),\n    Err(e) => return Err(e),\n}","preventionTips":["Give every statement/set result a unique name; never load_result the same name twice","Cache the loaded value in a variable and pass it around instead of re-fetching","Reserve the name 'main' for results that are intentionally re-readable","Track loaded result names in macro-local state when composing multiple macros"],"tags":["jinja","state","result-store","dbt"],"backgroundTag":"invalid-state-transition","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}