sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

SQLite UPDATE FROM statements not supported

Open alexbakker opened this issue 1 year ago • 2 comments

Version

1.25.0

What happened?

I tried to use a SQLite UPDATE FROM statement, but sqlc failed to parse it.

Relevant log output

line 4:0 extraneous input 'FROM' expecting {<EOF>, ';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}
line 4:27 no viable alternative at input 'node'
# package 
query.sql:1:1: no viable alternative at input 'node'

Database schema

CREATE TABLE node (
  id   INTEGER PRIMARY KEY,
  name TEXT NOT NULL
);

CREATE TABLE node_address (
  id INTEGER PRIMARY KEY,
  node_id INTEGER NOT NULL,
  hostport TEXT NOT NULL,
  pinged_at REAL,
  FOREIGN KEY (node_id) REFERENCES node (id)
);

SQL queries

-- name: PingNodeAddress :exec
UPDATE node_address
SET pinged_at = unixepoch('subsec')
FROM (SELECT id, name FROM node) AS n
WHERE node_address.node_id = n.id AND node_address.hostport = ? AND n.name = ?;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "sqlite",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/b3a24492f28da8e2fa4189d99731f42a02e7f481d7ac7a6aaeca4eaf1c979ec3

What operating system are you using?

Linux

What database engines are you using?

SQLite

What type of code are you generating?

Go

alexbakker avatar Jan 13 '24 20:01 alexbakker

@alexbakker I'm also running into this. Did you manage to find a workaround?

Voles avatar Apr 18 '24 19:04 Voles