我正在使用spanner nodejs客户端库。 我需要请求查询:
database.run({
sql: `SELECT * FROM Goods@{FORCE_INDEX=GoodsByCodeName} WHERE (code, name) in UNNEST(@codesNames)`,
params: {codesNames: codesNames}}, ...
如何指定array_parameter
的代码类型 - 代码数组[{string, string},...]
答案 0 :(得分:2)
Cloud Spanner尚不支持对象类型参数。为了解决这个问题,您可以将对象分解为每个字段的并行数组参数,将它们连接到偏移量以创建一个子查询,该子查询具有与对象类型(code<STRING>, name<STRING>)
相同类型的行,并加入该子查询你的桌子是这样的:
SELECT * FROM Goods@{FORCE_INDEX=GoodsByCodeName} g
JOIN (
SELECT p.code, q.name from
(SELECT code, o_code FROM UNNEST(@code_array) as code WITH OFFSET o_code) p
JOIN
(SELECT name, o_name FROM UNNEST(@name_array) as name WITH OFFSET o_name) q
ON p.o_code = q.o_name)
) r ON g.code = r.code and g.name = r.name
答案 1 :(得分:0)
我改变选择:
database.run({
sql: `SELECT * FROM Goods WHERE (code, name) in (SELECT (code, name) FROM (UNNEST (@codes) as code WITH OFFSET AS num JOIN UNNEST (@names) as name WITH OFFSET AS num using(num)))`,
params: {codes: codes, names: names},....