<p>MySQL raises error 1758 when a SIGNAL or RESIGNAL statement references an invalid or out-of-range numeric condition.</p>
<p>MySQL Error 1758 ER_DA_INVALID_CONDITION_NUMBER appears when a stored routine signals a numeric condition outside the 1-65535 range or one not declared locally. Correct the number or use SQLSTATE to resolve it.</p>
Invalid condition number
Error 1758 appears when a SIGNAL or RESIGNAL statement refers to a numeric condition value that MySQL cannot resolve. The server returns SQLSTATE 35000 with the message Invalid condition number and stops executing the routine.
The problem is specific to stored procedures, functions, triggers, and events that raise custom errors. MySQL allows only unsigned smallint values 1-65535 or a previously declared named condition.
Developers often copy code where condition numbers start at zero or exceed 65535. Mistyped literals, negative values, and references to removed DECLARE CONDITION definitions also trigger error 1758.
Upgrading to a new server version that reserves additional condition numbers can suddenly invalidate older routines.
Audit each SIGNAL statement. Replace illegal numbers with values 1-65535 that are not reserved, or switch to SQLSTATE signalling which is always safe. Add a local DECLARE CONDITION if you need a custom name and number mapping.
After changes, recompile the routine and rerun unit tests to confirm the fix.
An ALTER PROCEDURE that removed a DECLARE CONDITION but kept a SIGNAL will fail; re-introduce the declaration. Importing routines from Oracle PL/SQL with large numeric codes requires remapping to accepted ranges.
Generated code from ORMs may default to 0; adjust generator templates to emit SQLSTATE instead.
Standardize on SQLSTATE-based signalling, maintain a lookup table of approved numeric codes, and enforce code review checks. Galaxy's linting rules flag out-of-range numbers in real time.
Error 1645 (ER_SIGNAL_BAD_CONDITION_TYPE) occurs when SIGNAL uses both SQLSTATE and condition number. Error 1367 (ER_CRASHED_ON_USAGE) involves invalid routine usage. Fixes follow similar validation steps.
Using a value below 1 or above 65535 immediately raises error 1758.
SIGNAL references a condition name that has been deleted or moved.
The routine uses a numeric code later reserved by MySQL itself after an upgrade.
ORM or template emits 0 or negative numbers instead of valid SQLSTATE.
Raised when both SQLSTATE and condition number are supplied, causing ambiguity.
Occurs when SIGNAL references an undeclared condition name.
Indicates that stored routine definitions are corrupted or inconsistent.
No. MySQL starts valid numeric conditions at 1. Zero triggers error 1758.
Yes. SQLSTATE values are portable and never conflict with MySQL reserved numbers.
Rarely, but new reserved codes can emerge. Review release notes before upgrading.
Galaxy's live parser flags out-of-range numbers and suggests SQLSTATE refactors inside the editor.