{"record":{"id":"950f8a0b381021f6","repo":"iflytek/astron-agent","slug":"pg-sql-param-error-database-dml-statement-generation-failed","errorCode":"PG_SQL_PARAM_ERROR","errorMessage":"Database DML statement generation failed: WHERE condition is empty","messagePattern":"Database DML statement generation failed: WHERE condition is empty","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/nodes/pgsql/pgsql_node.py","lineNumber":269,"sourceCode":"\n            else:\n                if op in (\"LIKE\", \"NOT LIKE\"):\n                    val = f\"%{val}%\"\n                placeholder = f\":w_val_{w_idx}\"\n                part = f\"{fld} {op} {placeholder}\"\n                params[f\"w_val_{w_idx}\"] = val\n                w_idx += 1\n\n            parts.append(part)\n\n        # Combine conditions with logical operator\n        where_clause = f\" {case.logicalOperator.upper()} \".join(parts)\n        if where_clause:\n            sql = f\"UPDATE {self.tableName} SET {set_clause} WHERE {where_clause};\"\n            stmt = text(sql).bindparams(**params)\n            return str(stmt.compile(compile_kwargs={\"literal_binds\": True}))\n        else:\n            raise CustomException(\n                err_code=CodeEnum.PG_SQL_PARAM_ERROR,\n                err_msg=\"Database DML statement generation failed: WHERE condition is empty\",\n                cause_error=\"Database DML statement generation failed: WHERE condition is empty\",\n            )\n\n    def generate_delete_statement(self, case: Case) -> str:\n        \"\"\"Generate DELETE SQL statement with WHERE conditions.\n\n        :param condition: Dictionary containing WHERE clause conditions\n        :return: Formatted DELETE SQL statement\n        :raises CustomException: If WHERE conditions are empty or invalid\n        \"\"\"\n        # Build WHERE clause conditions for DELETE statement\n        parts = []\n        params = {}\n        idx = 0\n\n        for condition in case.conditions:","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/nodes/pgsql/pgsql_node.py#L251-L287","documentation":"`generate_update_statement` builds the WHERE clause for an UPDATE from the configured cases. If joining the case parts yields an empty WHERE clause (e.g. all cases rendered empty), it refuses to emit an UPDATE without a WHERE and raises PG_SQL_PARAM_ERROR, preventing a full-table update.","triggerScenarios":"Calling `generate_dml` for an UPDATE node where every Case in `cases` produces an empty SQL fragment (empty column/value templates, all-None evaluated parts) so `where_clause` is falsy despite passing model validation.","commonSituations":"Case fields reference workflow variables that resolved to empty strings; template placeholders left unfilled; cases populated with blank rows via API that bypassed UI validation.","solutions":["Inspect the node's cases and ensure each has a non-empty column, operator, and a resolvable value.","Check upstream variable references in case values — unresolved variables may render as empty strings and drop the condition.","Add a pre-check in generate_update_statement that filters out blank parts and errors earlier with a per-case message.","Re-save the node in the editor so validators re-run and surface the incomplete condition to the author."],"exampleFix":"// before\ncases=[Case(column=\"\", operator=\"=\", value=\"{{var}}\")]  # renders empty WHERE\n// after\ncases=[Case(column=\"id\", operator=\"=\", value=\"42\")]","handlingStrategy":"validation","validationCode":"def cases_render_nonempty(cases):\n    return all(c.column and c.column.strip() and c.value not in (None, \"\") for c in cases)","typeGuard":"def update_has_where(cfg) -> bool:\n    return cfg.mode != 2 or cases_render_nonempty(cfg.cases)","tryCatchPattern":"try:\n    sql = await node.generate_dml(span)\nexcept CustomException as e:\n    if \"WHERE condition is empty\" in str(e):\n        log.error(\"UPDATE would run without WHERE; check case values/variables\")\n    raise","preventionTips":["Ensure case values referencing workflow variables are resolved before execution","Reject blank condition rows in the editor UI","Log evaluated case parts during debugging to spot empty fragments"],"tags":["sql","validation","safety","dml"],"backgroundTag":"empty-required-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}