在 ESQL 中访问动态字段名称

Access dynamic field name in ESQL

我需要使用 ESQL 创建和访问动态字段名称。请提出您的意见。

下面函数中字段 dynamicFieldName 的来源来自 table.

CREATE FUNCTION getFieldValue(IN Environment REFERENCE, IN userId CHARACTER, IN dynamicFieldName CHARACTER) RETURNS CHARACTER
BEGIN
   RETURN THE (SELECT ITEM FIELDVALUE(ref.dynamicFieldName) FROM Environment.Variables.dbData[] AS ref where ref.USER_ID = userId);
END;

这个函数抛出错误

BIP2492E: Illegal type parameter '1' of the function 'FIELDVALUE'. A non-list field reference is required.

ESQL field reference overview 解释了您的要求:

Because the names of the fields appear in the ESQL program, they must be known when the program is written. This limitation can be avoided by using the alternative syntax that uses braces ( { ... } ). This syntax allows you to use any expression that returns a non-null value of type character.

因此您的代码应如下所示:

FIELDVALUE(ref.{dynamicFieldName})