sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Inserts are not typechecked at all

Open alarbada opened this issue 3 years ago • 1 comments

Version

1.15.0

What happened?

The following example produces a query that will always fail, so IMHO it should result into a compilation error.

Relevant log output

No response

Database schema

create table test (
	a character varying not null,
	b character varying not null
);

SQL queries

-- name: Test :exec
insert into test (a)
values ($1);

Configuration

version: '2'
sql:
    - schema: 'pg/schema.sql'
      queries:
          - 'pg/queries.sql'
          - 'pg/alerts.sql'
      engine: 'postgresql'
      gen:
          go:
              sql_package: 'pgx/v4'
              package: 'pg'
              out: 'pg'

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

alarbada avatar Aug 26 '22 14:08 alarbada

I'll need to investigate how a few other SQL analyzers work, as I'm not sure this is something sqlc will be able to support at some point.

kyleconroy avatar Aug 29 '22 03:08 kyleconroy

Coming back to this, we've considered how to use the not null constraint information to add a compile-time check for an insert that will fail but it's not obvious how we'd do it given that the query is preparable. So I'm closing this as wontfix for now, although we may want to consider at a later date.

andrewmbenton avatar Oct 16 '23 21:10 andrewmbenton