ydb-platform / ydb-platform/ydb-sqlalchemy

Bug: Incorrect SQL generated for `UPSERT INTO ... SELECT`

Open
#78 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai_reviewed
Dominant language
Python
Stars
40
Forks
13
Avg merge
2d 6h
Merged PRs (30d)
3

Description

Hi guys,

Thank you for the great work on this library.

I've encountered an issue where UPSERT INTO ... SELECT FROM generates invalid YQL. This also likely affects INSERT INTO ... SELECT. YDB supports this syntax natively (UPSERT docs, INSERT docs), but the generated query fails because it incorrectly includes the target table in the FROM clause.

Example of the faulty generated query:

UPSERT INTO my_table (col1, col2) 
SELECT my_table.col1, my_table.col2
FROM as_table(%(my_input)s), my_table

The extra my_table in the FROM clause and columns in brackets causes the query to fail. Could you please look into fixing the query generation logic?
Thanks for your help!

Contributor guide

No contributing guide indexed for this repository

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 by tracing the SQL generation logic for UPSERT INTO ... SELECT and compare it with the INSERT INTO ... SELECT path. Use the faulty query and the linked YDB UPSERT and INSERT documentation as references; done means the generated YQL omits the target table from FROM and avoids the invalid column brackets for both forms.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.