Skip to main content

Example 1: Storing Data in Internal Variable

In Kvery, we utilize internal variables to store an array of data. These variables are denoted as “:var”. For instance, a sample code to store data in an internal variable could be:

 :var = (Select customerNumber From customers Where country = 'USA');

If we return this variable, it displays a JSON list containing the customerNumbers from the customers table.

return(:var);

The results:

112, 124, 129, 131, 151, 157, 161, 168, 173, 175, 181, 198, 204, 205, 219, 239, 286, 319, 320, 321, 328, 339, 347, 362, 363, 379, 424, 447, 450, 455, 456, 462, 475, 486, 487, 495

The primary purpose of this function is to store data in a variable, which simplifies code readability and aids in optimizing query runtime. Consider, for instance, wanting to access payment information for these customers from the payments table.

The code would then be the following:

:var = (
Select
customerNumber
From
customers
Where
country = 'USA'
);

Select
*
From
payments
Where
customerNumber IN (:var);

Ultimately, this method yields all data from the payment table for customers based in the USA. Employing this approach allows us to work independently with the variable, streamlining the coding process. Additionally, it eliminates the need to join tables, thereby enhancing runtime efficiency.

Name