sqlalchemy / sqlalchemy/sqlalchemy

Select Values in Mysql

Open
#10,310 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code review in progress mysql sql use case
Dominant language
Python
Stars
12.2k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Discussed in https://github.com/sqlalchemy/sqlalchemy/discussions/10309

Originally posted by RasulGafarov September 4, 2023
The following code:

my_select = select(
            Values(
                sqlalchemy.column("column_1", String),
                sqlalchemy.column("column_1", String),
                name="temp_1", literal_binds=True
            ).data([("a", "2"), ("b", "3")]))

generates sql:

SELECT temp_1.column_1, temp_1.column_1 AS column_1_1 
FROM (VALUES ('a', '2'), ('b', '3')) AS temp_1 (column_1, column_1)

this code causes an error because mysql (8.0.33) requires the following syntax:

SELECT temp_1.column_1, temp_1.column_1 AS column_1_1
FROM (VALUES ROW('a', '2'), ROW('b', '3')) AS temp_1 (column_1, column_1)

https://dev.mysql.com/doc/refman/8.0/en/values.html

how to fix this error? Thank you in advance

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the Values and select entry points that produce the shown SQL, then compare the MySQL 8.0.33 VALUES syntax in the linked MySQL documentation. Reproduce the generated query against MySQL and verify that the resulting SQL uses the required ROW form and executes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, python, sqlalchemy
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.