Skip to content

SQLite UPDATE FROM statements not supported #3132

Open
@alexbakker

Description

@alexbakker

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions