vertica/vertica-sql-go

null args results in error

eldadts opened this issue · 4 comments

for example when performing

query := "INSERT INTO test.my_table (name, age) VALUES (?,?)"
_, err = tx.ExecContext(ctx, query, 1, nil)

it returns Error: [22V02] Invalid input syntax for float: \"??HELP??\""
Debugging the statement shows it is not adding AS NULL::float to the copy command.

Same for int type.
In VARCHAR type it just inserts the text "??HELP??"

workaround is to replace the ? with "null" in the query string in its relative position - but it is quite an overhead...

Hello @xtrimf. Would you please provide a complete reproducer? And your Golang version.

query := 'INSERT INTO test.my_table (name, age) VALUES (?,?)'

The single quote '' is used to declare characters (rune, char). In Golang, a string should be defined within double quotes or back quotes. I'm not sure if this is related to your problem.

@sitingren the quote ' is just a typo, I actually use " - so its not a rune issue (I updated the post)

Go 1.15.6

in vertica:

CREATE TABLE test.table (
name varchar(100),
age float DEFAULT NULL::float
)

Go:

dbConnection := fmt.Sprintf("vertica://%s:%s@%s:%d/%s", "dbadmin", "**********", "vertica-test.com", 5433, "prod")
db, err := sql.Open("vertica", dbConnection)
if err != nil {
    l.Log.Fatal().Err(err).Caller().Msg("can't open db")
}
defer db.Close()
ctx := context.Background()
err = db.PingContext(ctx)
if err != nil {
	l.Log.Fatal().Err(err).Caller().Msg("can't reach db")
}
query := "INSERT INTO tests.table (name, age) VALUES (?,?)"
values := []interface{}{"name", 30.5}
tx, _ := db.BeginTx(ctx, nil)
_, err = tx.ExecContext(ctx, query, values...)
if err != nil {
    l.Log.Panic().Err(err).Caller().Msg("error performing query")
}
tx.Commit()

@xtrimf I cannot reproduce your problem. Are you running with the latest version of vertica-sql-go? I found there is a fix (#92) that addressed similar issue.

tnx @sitingren !,
I missed that update.