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

statement expects 0 inputs; got 1 while using sql.NamedArgs #22

Closed
marcelcorso opened this issue Mar 22, 2017 · 7 comments
Closed

statement expects 0 inputs; got 1 while using sql.NamedArgs #22

marcelcorso opened this issue Mar 22, 2017 · 7 comments
Assignees
Labels

Comments

@marcelcorso
Copy link

On go 1.8 the sql package started to support NamedArgs.

I just tried to add

        rows, err = connect.Query("SELECT * FROM example WHERE os_id = @os_id", sql.Named("os_id", 10))
        if err != nil {
                log.Fatal(err)
        }

to the simple.go example and got the error

[clickhouse]host(s)=127.0.0.1:9000, database=default, username=default
[clickhouse][hello] -> Golang SQLDriver 1.1.54126
[clickhouse][hello] <- ClickHouse 1.1.54180 (Etc/UTC)
[clickhouse][prepare] SELECT * FROM example WHERE os_id = @os_id
[clickhouse][stmt] close
2017/03/22 15:27:22 sql: statement expects 0 inputs; got 1
$> go version
go version go1.8 linux/amd64
@kshvakov kshvakov self-assigned this Mar 22, 2017
@kshvakov kshvakov added the bug label Mar 22, 2017
@kshvakov
Copy link
Collaborator

Hi, full features Go 1.8 is't supported of current driver version. I'll be add NamedArgs support in the next couple of days

thank you

kshvakov added a commit that referenced this issue Mar 23, 2017
@marcelcorso
Copy link
Author

thanks @kshvakov. I tested the changes on 2 places and it worked. Code is 👍 too.

@marcelcorso
Copy link
Author

marcelcorso commented Mar 28, 2017

The code

rows, err = connect.Query("SELECT * FROM example WHERE os_id = @os_id AND browser_id = @os_id",  sql.Named("os_id", 10))

fails with

2017/03/24 09:58:33 sql: statement expects 2 inputs; got 1

I didn't find any specific recommendation on how this should work and there are no tests for this specific case on the sql package
https://github.com/golang/go/blob/master/src/database/sql/sql_test.go#L513

but it feels it should work.

@marcelcorso
Copy link
Author

golang/go#12381

kshvakov added a commit that referenced this issue Mar 28, 2017
@marcelcorso
Copy link
Author

marcelcorso commented Mar 28, 2017

Thanks @kshvakov that was fast.

But this

rows, err = connect.Query("SELECT * FROM example WHERE os_id in (@os_id,@browser_id) browser_id = @browser_id", sql.Named("os_id", 10), sql.Named("browser_id", 77))

(note the lack of space between @os_id,@browser_id

breaks with the message

sql: statement expects 1 inputs; got 2

And with the space between the parameters

rows, err = connect.Query("SELECT * FROM example WHERE os_id IN (@os_id, @browser_id) AND browser_id = @browser_id", sql.Named("os_id", 10), sql.Named("browser_id", 77))

I get a different error:

code: 62, message: Syntax error: failed at position 39: @os_id, @browser_id) AND browser_id = 77, expected )

@kshvakov
Copy link
Collaborator

Yes, I know. I'll fix this problem in the next couple of days

@kshvakov kshvakov reopened this Mar 28, 2017
kshvakov added a commit that referenced this issue Mar 29, 2017
@marcelcorso
Copy link
Author

I just tested the new code with a bunch of use cases and it looks good. 👍

mshustov pushed a commit that referenced this issue Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants