houqp / houqp/sqlvet

Update-Queries with multiple tables do not work properly

Open
#11 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
500
Forks
29
PR merge metrics
No merged PRs in 30d

Description

I just ran into an issue with one of my queries and it seems sqlvet cannot handle this sort of Update-Query:

UPDATE activities u
	SET ref_id = c.ref_id
FROM activities c 
WHERE u.object_id = c.object_id 
	AND c.event_type = 'create'
	AND u.event_type = 'update'
	AND u.ref_id <= 0

The Error-Message is

ERROR: table `u` not available for query

Currently I just ignore this one query using the //sqlvet:ignore but it would be nice to have it fixed.

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 by reproducing the provided UPDATE ... FROM query and trace how sqlvet resolves table aliases in multi-table updates. The issue is done when this query is analyzed without the table u not available error and the existing ignore workaround is no longer needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.