sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Field name not respected when using `NULLIF` in insert query

Open go-mez opened this issue 3 years ago • 1 comments

Version

1.12.0

What happened?

When generating an insert query using the NULLIF function, the field name is not respected and will be generated as nullif.

Relevant log output

type CreateAlarmParams struct {
	NULLIF    interface{}
	CreatedBy sql.NullInt32
}

Database schema

CREATE TABLE alarms (
	alarm_title varchar(30),
  	created_by int(11)
);

SQL queries

-- name: CreateAlarm :execresult
INSERT INTO alarms (
  alarm_title, 
  created_by
) VALUES 
(
  NULLIF(?, ''), 
  ?
);

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "mysql",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/fbe1bfb0158f637dd53b3ad90e19ecdc59c27fbf7568cd332b9a120af81f39cc

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

go-mez avatar Mar 22 '22 20:03 go-mez

@go-mez would my proposal for giving the developer control of the input and output parameters to the query (including naming, nullability, etc) solve this issue for you?

https://github.com/kyleconroy/sqlc/issues/1506

skabbes avatar Apr 02 '22 18:04 skabbes

sqlc.arg can at least get you a better name https://play.sqlc.dev/p/1642ad7238085024e55559bdb875cf8928b39ab0521045df66289a6bc798505d

kyleconroy avatar Sep 22 '23 20:09 kyleconroy