Skip to content
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

NullEnums.Value() breaks SQL-Execution #1880

Closed
Neokil opened this issue Oct 5, 2022 · 0 comments · Fixed by #1996
Closed

NullEnums.Value() breaks SQL-Execution #1880

Neokil opened this issue Oct 5, 2022 · 0 comments · Fixed by #1996

Comments

@Neokil
Copy link

Neokil commented Oct 5, 2022

Version

1.15.0

What happened?

I have an Entity that I want to either select all or filter by mode. The SQL looks like this:

SELECT *
FROM entity
WHERE (mode IN (sqlc.narg(mode)) OR sqlc.narg(mode) IS NULL)

This generates a struct called NullMode and a Value() function for it

type Mode string

type NullMode struct {
	Mode  Mode
	Valid bool // Valid is true if String is not NULL
}

func (ns NullMode) Value() (driver.Value, error) {
	if !ns.Valid {
		return nil, nil
	}
	return ns.Mode, nil
}

Now when this gets executed I am getting the following Error-Message:

sql: converting argument $1 type: non-Value type analytics.Mode returned from Value

This can be easily fixed by adding a string-cast to the Value-Return like this:

return string(ns.Mode), nil

Relevant log output

No response

Database schema

CREATE TYPE mode AS ENUM (
    'live',
    'shadow'
);

CREATE TABLE entity (
    id   SERIAL PRIMARY KEY,
    mode mode NOT NULL DEFAULT 'shadow'
)

SQL queries

No response

Configuration

No response

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@Neokil Neokil added bug Something isn't working triage New issues that hasn't been reviewed labels Oct 5, 2022
@kyleconroy kyleconroy added 💻 darwin 📚 postgresql 🔧 golang and removed triage New issues that hasn't been reviewed labels Nov 9, 2022
@kyleconroy kyleconroy added this to the v1.17.0 milestone Nov 9, 2022
mcdoker18 added a commit to mcdoker18/sqlc that referenced this issue Dec 13, 2022
The Value method must returns nil or the following types:

* int64
* float64
* bool
* []byte
* string
* time.Time

Closes: sqlc-dev#1880
kyleconroy pushed a commit that referenced this issue Jan 2, 2023
The Value method must returns nil or the following types:

* int64
* float64
* bool
* []byte
* string
* time.Time

Closes: #1880
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants