Skip to content

SQLite upsert does not work #1728

Description

@Elara6331

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

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Jul 7, 2022
  2. talksik commented on Mar 29, 2024

    @talksik

    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

  3. talksik commented on Mar 30, 2024

    @talksik

    Oh thank you @orisano ! Appreciate ya :)

  4. sztanpet commented on Jun 30, 2024

    @sztanpet

    Still happening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions