{"record":{"id":"28f91ce79db755ad","repo":"risingwavelabs/risingwave","slug":"null-value-in-column-col-name-of-relation-ta","errorCode":null,"errorMessage":"null value in column \"{col_name}\" of relation \"{table_name}\" violates not-null constraint","messagePattern":"null value in column \"(.+?)\" of relation \"(.+?)\" violates not-null constraint","errorType":"exception","errorClass":"ExprError","httpStatus":null,"severity":"error","filePath":"src/expr/core/src/error.rs","lineNumber":111,"sourceCode":"    Internal(\n        #[from]\n        #[backtrace]\n        anyhow::Error,\n    ),\n\n    #[error(\"not a constant\")]\n    NotConstant,\n\n    #[error(\"Context {0} not found\")]\n    Context(&'static str),\n\n    #[error(\"field name must not be null\")]\n    FieldNameNull,\n\n    #[error(\"too few arguments for format()\")]\n    TooFewArguments,\n\n    #[error(\n        \"null value in column \\\"{col_name}\\\" of relation \\\"{table_name}\\\" violates not-null constraint\"\n    )]\n    NotNullViolation {\n        col_name: Box<str>,\n        table_name: Box<str>,\n    },\n\n    #[error(\"invalid state: {0}\")]\n    InvalidState(String),\n\n    /// Function error message returned by UDF.\n    /// TODO: replace with `Function`\n    #[error(\"{0}\")]\n    Custom(String),\n\n    /// Error from a function call.\n    ///\n    /// Use [`ExprError::function`] to create this error.","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/expr/core/src/error.rs#L93-L129","documentation":"ExprError::NotNullViolation { col_name, table_name } is thrown when an expression evaluation (e.g. producing rows for insert/update) yields NULL for a column that carries a NOT NULL constraint. The message mirrors Postgres: 'null value in column \"{col_name}\" of relation \"{table_name}\" violates not-null constraint'. It names the offending column and table so the data problem can be located.","triggerScenarios":"INSERT/UPDATE (including sink/materialized-view writes driven by expressions) computing NULL for a NOT NULL column — e.g. a join missing rows, a cast producing NULL, or a projection passing NULL through to a constrained column.","commonSituations":"Left joins introducing NULLs before an insert, nullable upstream columns inserted into NOT NULL tables, default expressions returning NULL, schema migrations adding NOT NULL columns without backfill.","solutions":["Wrap the projected expression in COALESCE with a sensible default for that column.","Filter out rows where the constrained column would be NULL before writing.","Relax the constraint (if acceptable) or backfill/repair the source data so NULLs no longer occur."],"exampleFix":"// before\nINSERT INTO users (id, nickname) SELECT id, nick FROM staging; -- nickname NOT NULL\n// after\nINSERT INTO users (id, nickname) SELECT id, COALESCE(nick, 'unknown') FROM staging;","handlingStrategy":"validation","validationCode":"-- guard NOT NULL targets before insert\nINSERT INTO users (id, nickname)\nSELECT id, COALESCE(nick, 'unknown') FROM staging WHERE id IS NOT NULL;","typeGuard":null,"tryCatchPattern":"// Extract col/table names for a data-quality alert\nif let Some(ExprError::NotNullViolation { col_name, table_name }) = err.downcast_ref::<ExprError>() {\n    alert(&format!(\"NULL in {table_name}.{col_name}\"));\n}","preventionTips":["COALESCE every expression feeding a NOT NULL column.","Beware left-join fan-out introducing NULLs before writes.","Backfill NOT NULL columns before enforcing the constraint on new data."],"tags":["rust","constraint","null"],"backgroundTag":"schema-validation-failed","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}