MySQL Forums
Forum List  »  Newbie

MySQL 8.0.13 deprecated the use of := for variable assignment within SELECT statements. What are some alternative approaches?
Posted by: Hiroki Morita
Date: February 15, 2024 02:38PM

Hello!

### What I'd Like to Know

Since MySQL 8.0.13, the usage of `:=` for variable assignment within SELECT statements has been deprecated. Although INTO is recommended as an alternative, it cannot be used when selecting multiple columns.

Using subqueries as an alternative is possible, but it can make queries complex, which is not desirable.

How have you been managing this?

### Examples

- Intuitive but non-working example:

```sql
SELECT
-- @uid := user_id Originally it was like this
user_id INTO @uid,
work_id
FROM
works
WHERE
work_id = 1;

```

- Working but complex example:

```sql
SELECT
(SELECT user_id FROM works WHERE work_id = 1) INTO @uid,
work_id
FROM
works
WHERE
work_id = 1;

```

### Other Considerations

In cases where variables are assigned within a query but not used, is it acceptable to use the deprecated `:=` method as before? I've heard that `:=` was deprecated because it could lead to unexpected issues, but I think for simple use cases, there shouldn't be any issues.

If there were discussions or issues leading up to the deprecation, I'd appreciate being informed about them.

Options: ReplyQuote


Subject
Written By
Posted
MySQL 8.0.13 deprecated the use of := for variable assignment within SELECT statements. What are some alternative approaches?
February 15, 2024 02:38PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.