Common SQL Errors

MySQL Error 1309: ER_SP_LABEL_REDEFINE – How to Fix and Prevent

Galaxy Team
August 6, 2025

The label-redefine error appears when a stored program declares the same label twice in the same scope.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1309 ER_SP_LABEL_REDEFINE?

MySQL Error 1309 ER_SP_LABEL_REDEFINE arises when a stored procedure or trigger declares the same label more than once within the same scope. Rename or remove the duplicate label, then re-run the routine to resolve the issue.

Error Highlights

Typical Error Message

Redefining label %s

Error Type

Syntax Error

Language

MySQL

Symbol

ER_SP_LABEL_REDEFINE

Error Code

1309

SQL State

42000

Explanation

Table of Contents

What is MySQL error 1309 ER_SP_LABEL_REDEFINE?

Error 1309 is raised when MySQL encounters two identical labels in the same lexical scope of a stored procedure, function, trigger, or event. MySQL’s parser flags this as a syntax violation and aborts compilation.

The condition name ER_SP_LABEL_REDEFINE literally means "Stored Program Label Redefine." It protects control-flow integrity so that a LEAVE or ITERATE statement always resolves to a unique target.

What causes this error?

Duplicate labels inside a BEGIN…END block trigger the error immediately during CREATE or ALTER PROCEDURE execution. The conflict can be direct or through nested compound statements sharing the same label string.

Copy-pasted code, auto-generated templates, or refactors that forget to update label names are common triggers. MySQL 5.6-8.3 all enforce the rule.

How do I fix MySQL Error 1309 ER_SP_LABEL_REDEFINE?

Search the affected routine for repeated label identifiers. Rename one occurrence or remove the redundant block. Re-deploy the object after verifying with SHOW WARNINGS.

When labels are required in nested loops, add clear prefixes, for example outer_loop and inner_loop, to keep names unique.

Common scenarios and solutions

A FOR loop copied twice with the same loop_label will break compilation. Change the second to loop_label2.

Nested cursors that each use fetch_loop cause the same failure. Prefix the inner cursor label to fetch_loop_inner.

Best practices to avoid this error

Adopt a naming convention such as block__. Use code review or static analysis tools to catch duplicates before deployment.

Galaxy’s SQL editor highlights duplicate labels in real time, preventing the issue before you run DELIMITER commands.

Related Errors and Solutions

Error 1334 ER_SP_UNDECLARED_VAR appears when a variable is referenced before declaration. Ensure DECLARE lines precede usage.

Error 1335 ER_SP_DUP_PARAM flags duplicate parameter names. Rename overlapping parameters similarly to how you resolve label redefinitions.

Common Causes

Related Errors

FAQs

Do labels need to be globally unique across the database?

No. They only need to be unique within the compound statement scope of the stored program.

Can I disable label checking?

MySQL does not offer a flag to bypass label validation. Unique names are mandatory.

Does MySQL care about label case?

Labels are case sensitive on all platforms, so foo and FOO are treated as different.

How does Galaxy help prevent this error?

Galaxy’s real-time linter flags duplicate labels while you type, letting you rename them before executing the CREATE PROCEDURE statement.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo