Skip to content

Same parameter with two different types should error #297

Closed
@kevinburke1

Description

@kevinburke1

If I do something like

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL
);

-- name: UpdateAuthor :exec
UPDATE authors
SET name = $1
WHERE id = $1;

In theory this should error because $1 must either be a number or a text. PostgreSQL returns the following error when executing this query:

ERROR:  invalid input syntax for type bigint: "foo"

In practice sqlc is happy to allow it, generating the following code:

// Code generated by sqlc. DO NOT EDIT.
// source: query.sql

package querytest

import (
	"context"
)

const updateAuthor = `-- name: UpdateAuthor :exec
UPDATE authors
SET name = $1
WHERE id = $1
`

func (q *Queries) UpdateAuthor(ctx context.Context, name string) error {
	_, err := q.db.ExecContext(ctx, updateAuthor, name)
	return err
}

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