zabbarob
zabbarob

Reputation: 1201

What does `@` mean when not appending any variable name?

Playing around with MariaDB I accidentally found out that it's possible to use @ without giving a variable name. I executed following statement:

SELECT @ INTO @;

I would have expected a syntax error since the variable name was omitted, but instead it executes just fine. Now I'm wondering what is happening.

How does MariaDB interpret the @ symbol in this case? What does this SELECT actually do? Or is it just completely ignored without any further operation?

Upvotes: 0

Views: 36

Answers (1)

Barmar
Barmar

Reputation: 781741

Although neither the MySQL nor MariaDB documentation specifically mentions it, apparently user-defined variable are allowed to have an empty name. @ is the same as @'', and it's treated just like any other variable.

So

SELECT @ INTO @;

is like

SELECT @myvar INTO @myvar;

It's a useless statement, since it's just assigning a variable to itself, equivalent to

SET @ = @;

Upvotes: 3

Related Questions