Skip to content

SQLite upsert does not work #1728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Elara6331 opened this issue Jul 7, 2022 · 4 comments · Fixed by #1732
Closed

SQLite upsert does not work #1728

Elara6331 opened this issue Jul 7, 2022 · 4 comments · Fixed by #1732
Labels
📚 sqlite bug Something isn't working 💻 linux

Comments

@Elara6331
Copy link

Version

Other

What happened?

SQLite upsert syntax is not working using the beta SQLite engine from the latest main branch.

Relevant log output

mismatched input '=' expecting '=='

Database schema

CREATE TABLE IF NOT EXISTS locations (
    id              INTEGER PRIMARY KEY,
    name            TEXT    NOT NULL,
    address         TEXT    NOT NULL,
    zip_code        INT     NOT NULL,
    latitude        REAL    NOT NULL,
    longitude       REAL    NOT NULL,
    UNIQUE(name)
);

SQL queries

INSERT INTO locations (
    name,
    address,
    zip_code,
    latitude,
    longitude
)
VALUES (?, ?, ?, ?, ?)
ON CONFLICT(name) DO UPDATE SET 
    name = excluded.name,
    address = excluded.address
    zip_code = excluded.zip_code
    latitude = excluded.latitude
    longitude = excluded.longitude;

Configuration

No response

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

No response

What type of code are you generating?

Go

@Elara6331 Elara6331 added bug Something isn't working triage New issues that hasn't been reviewed labels Jul 7, 2022
@kyleconroy kyleconroy added 📚 sqlite 💻 linux go and removed triage New issues that hasn't been reviewed labels Jul 10, 2022
@talksik
Copy link

talksik commented Mar 29, 2024

Still not working for me:

-- name: UpsertUser :exec
INSERT INTO users (user_id, status)
VALUES (@userId, @newStatus)
ON CONFLICT (user_id) 
DO UPDATE SET status = @updatedStatus;

Generated:

const upsertUser = `-- name: UpsertUser :exec
INSERT INTO users (user_id, status)
VALUES (?1, ?2)
ON CONFLICT (user_id) 
DO UPDATE SET status = @updatedStatus
`

type UpsertUserParams struct {
	UserId    string
	NewStatus int64
}

func (q *Queries) UpsertUser(ctx context.Context, arg UpsertUserParams) error {
	_, err := q.db.ExecContext(ctx, upsertUser, arg.UserId, arg.NewStatus)
	return err
}

The last arg is not being parsed.

Tried updating sqlc as well: v1.26.0

@orisano
Copy link
Contributor

orisano commented Mar 30, 2024

@talksik
Copy link

talksik commented Mar 30, 2024

Oh thank you @orisano ! Appreciate ya :)

@sztanpet
Copy link

Still happening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 sqlite bug Something isn't working 💻 linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants