Name

eval — Evaluate the contents of string as an expression.

Syntax

eval(string)
              

The eval function has the following argument:

string

A literal string value that will be interpreted as a Patchworks Query Language expression.

Description

This function will attempt to compile the string value that is passed in as a Patchworks Query Language expression. If the compilation phase fails then an error is raised. If compilation succeeds then the expression is evaluated and the result returned.

The input string must effectively be a literal (either a literal string or an expression that evaluates to a literal string). The string is evaluated and parsed when the expression is defined in order to determine the data type of the result. Note that the result of compiling the string does not have to be a literal expression, values from database columns may be referenced.

If the expressions contain quoted strings then the quote characters will need to be marked with a '\' escape character to indicate that they are to be embedded and do no demarcate the end of the current string, for example the expression

'C'+1

would be contained in a string as

'\'C\'+1' 

The data type of the eval expression will be the data type of the compiled input expression

Examples

Formula

Description

Result

eval('1+2+3')Compile and run the expression. Only literals are used in the input string and expression reduces to a literal.

6

eval('\'C\'+1')

Compile and run the expression. Only literals are used in the input string and expression reduces to a literal.

'C1'

eval('D+1')Compile and run the expression. A database column (D) is used in the input string, so the result of this expression will depend on the value of D for the row that is being evaluated. 
eval(A+'hello')Compilation error occurs. The input makes use of a database column (A) and cannot be reduced a literal.