Description\n-----------\n\n``sql\nGET [CURRENT] DIAGNOSTICS\n{\n    statement_property\n    [, statement_property] ... \n  | CONDITION condition_number\n    condition_property\n    [, condition_property] ...\n}\n\nstatement_property:\n    variable = statement_property_name\n\ncondition_property:\n    variable  = condition_property_name\n\nstatement_property_name:\n    NUMBER\n  | ROW_COUNT\n\ncondition_property_name:\n    CLASS_ORIGIN\n  | SUBCLASS_ORIGIN\n  | RETURNED_SQLSTATE\n  | MESSAGE_TEXT\n  | MYSQL_ERRNO\n  | CONSTRAINT_CATALOG\n  | CONSTRAINT_SCHEMA\n  | CONSTRAINT_NAME\n  | CATALOG_NAME\n  | SCHEMA_NAME\n  | TABLE_NAME\n  | COLUMN_NAME\n  | CURSOR_NAME\n  | ROW_NUMBER\n`\n\nThe diagnostics area contains information about the errors, warnings and notes which were produced by the last SQL statement. If that statement didn't produce any warnings, the diagnostics area contains information about the last executed statement which involved a table. The GET DIAGNOSTICS statement copies the requested information from the diagnostics area to the specified variables. It is possible to use both user variables or local variables.\n\nTo use GET DIAGNOSTICS, it is important to know how the diagnostics area is structured. It has two sub-areas: the statement information area and the error conditions information area. For details, please refer to the diagnostics area page.\n\nEach single GET DIAGNOSTICS command can read information from the statement information area or from a single error condition. This means that, if you have two warnings and you want to know the number of warnings, and read both the warnings, you need to issue GET DIAGNOSTICS three times.\n\nThe CURRENT keywords adds nothing to the statement, because MariaDB has only one diagnostics area.\n\nIf GET DIAGNOSTICS produces an error condition (because the command is properly parsed but not correctly used), the diagnostics area is not emptied, and the new condition is added.\n\nGetting Information from a Condition\n\nTo read information from a condition, the CONDITION keyword must be specified and it must be followed by the condition number. This number can be specified as a constant value or as a variable. The first condition's index is 1. If the error condition does not exist, the variables will not change their value and a 1758 error will be produced ("Invalid condition number").\n\nThe condition properties that can be read with GET DIAGNOSTICS are the same that can be set with SIGNAL and RESIGNAL statements. They are explained in the diagnostics area page. However, there is one more property: RETURNED_SQLSTATE, which indicates the condition's SQLSTATE.\n\nFor a list of SQLSTATE values and MariaDB error codes, see MariaDB Error Codes.\n\nThe type for all the condition properties is VARCHAR(64), except for MYSQL_ERRNO, whose valid range is 1 to 65534.\n\nROW_NUMBER\n\nYou can use the ROW_NUMBER property to retrieve the row number, too, even if the error text does not mention it. This property is named ERROR_INDEX . ROW_NUMBER is a reserved word.\n\nThere is no way, short of parsing the error text, to know in what row an error had happened.\n\nExamples\n--------\n\nCREATE TABLE test.t (c` INT) ENGINE = x;\nQuery OK, 0 rows affected, 2 warnings (0.19 sec)\n\nGET DIAGNOSTICS @num_conditions = NUMBER;\n\nSELECT @num_conditions;\n+-----------------+\n| @num_conditions |\n+-----------------+\n|               2 |\n+-----------------+\n\nURL: https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-diagnostics/get-diagnostics