What type of data should be inserted into map?
dinahosl opened this issue · 2 comments
dinahosl commented
Hi,
I'm stuck at the moment with inserting data into a table with a map field.
data := map[interface{}]interface{}{"test": 1}
_, err = s.conn.Execute("INSERT INTO t VALUES(1, ?)", []interface{}{data})
if err != nil {
return err
}error: Parameter 'c' was not found in the statement (ClientError, code 0xa1), see ./src/box/bind.c line 201
--
--
CREATE TABLE t
(
a INTEGER PRIMARY KEY UNIQUE,
b MAP
) WITH ENGINE = 'memtx';Help please..
oleg-jukovec commented
It looks like an error, but Tarantool interpreters a map in arguments like a extra-parameters table. The workaround is to pass the map via the extra-parameters table:
https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_sql/execute/
func TestSQLMap(t *testing.T) {
test_helpers.SkipIfSQLUnsupported(t)
conn := test_helpers.ConnectWithValidation(t, server, opts)
defer conn.Close()
_, err := conn.Execute("CREATE TABLE t (a INTEGER PRIMARY KEY UNIQUE, b MAP) WITH ENGINE = 'memtx';", []interface{}{})
if err != nil {
t.Errorf("Failed to create the table: %s", err)
}
data := map[string]interface{}{"test": 1}
tuple := map[string]interface{}{":b": data}
_, err = conn.Execute("INSERT INTO t VALUES(1, :b)", []interface{}{tuple})
if err != nil {
t.Errorf("Failed to insert data into the table: %s", err)
}
}
DinahoDSGN commented
@oleg-jukovec thank you very much