@GENERATED Directive

Directive @generated generates a field from existing fields/columns of the table or from SQL expressions.

Directive @generated takes optional argument path or sql, with an value that’s used to calculate the JSON field value. The path value is a SQL/JSON path expression. The sql value is a SQL expression or query. Note that, when using the GraphQL table function, the only supported argument is the sql. The path argument is available only for creating duality-views.

Note:

The following example finds the race month using a sql expression:

SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
    query getRaceMonths {
        race {
            id: race_id
            name
            month @generated(sql: "regexp_substr(race_date, ''[^-]+'', 1, 2)")
        }
    }
');

Which produces the following output containing the race month:

DATA
--------------------------------------------------------------------------------
{
  "id" : 201,
  "name" : "Bahrain Grand Prix",
  "month" : "MAR"
}

{
  "id" : 202,
  "name" : "Saudi Arabian Grand Prix",
  "month" : "MAR"
}

{
  "id" : 203,
  "name" : "Australian Grand Prix",
  "month" : "MAR"
}

{
  "id" : 204,
  "name" : "Japanese Grand Prix",
  "month" : "APR"
}
.......................
.......................
24 rows selected.