Pass-Through Functions (RAWSQL)

These RAWSQL pass-through functions can be used to send SQL expressions directly to the database, without first being interpreted by Tableau. If you have custom database functions that Tableau doesn't know about, you can use these pass-through functions to call these custom functions.

Because Tableau does not interpret the expression, you must define the aggregation when necessary. You can use the RAWSQLAGG version of a function when you need to pass an aggregated expression. RAWSQL pass-through functions may not work with federated (combined across different databases) or published data sources.

RAWSQL Syntax

RAWSQL functions have two types, disaggregated and aggregated. This is specified in the first part of the function name, RAWSQL or RAWSQLAGG. Next, an underscore. The final portion of the function name is the output type, such as BOOL, STR, or INT. In all RAWSQL functions, the argument is ("sql_expr", [arg1], ...[arg2]). When writing the function, you can use a substitution syntax (%n) to insert the correct field name or expression.

Your database usually will not understand the field names that are shown in Tableau. Because Tableau does not interpret the SQL expressions you include in the pass-through functions, using the Tableau field names in your expression may cause errors. Use %n to insert the correct field name or expression for a Tableau calculation into pass-through SQL.

For example, if you had a function that computed the median of a set of values, you could call that function on the Tableau column [Sales] like this:

RAWSQLAGG_REAL("MEDIAN(%1)", [Sales])
  • REALSQLAGG because you want to specify the aggregation.
  • REAL because the output is numeric and not necessarily an integer.
  • MEDIAN is the aggregation.
  • %1 is the placeholder for [Sales].

RAWSQL Functions

The following RAWSQL functions are available in Tableau.

The SQL expression is passed directly to the underlying database. Use %n in the SQL expression as a substitution syntax for database values.

RAWSQL_BOOL

Syntax RAWSQL_BOOL("sql_expr", [arg1], …[argN])
Output Boolean
Definition Returns a Boolean result from a given SQL expression.
Example
RAWSQL_BOOL("%1 > %2", [Sales], [Profit])

In the example, %1 is equal to [Sales] and %2 is equal to [Profit].

RAWSQLAGG_BOOL

Syntax RAWSQLAGG_BOOL("sql_expr", [arg1], …[argN])
Output Boolean
Definition Returns a Boolean result from a given aggregate SQL expression.
Example
RAWSQLAGG_BOOL("SUM( %1) >SUM( %2)", [Sales], [Profit]) 

In the example, %1 is equal to [Sales] and %2 is equal to [Profit].

 

RAWSQL_DATE

Syntax RAWSQL_DATE("sql_expr", [arg1], …[argN])
Output Date
Definition Returns a date result from a given SQL expression.
Example
RAWSQL_DATE("%1", [Order Date])

In this example, %1 is equal to [Order Date].

RAWSQLAGG_DATE

Syntax RAWSQLAGG_DATE("sql_expr", [arg1], …[argN])
Output Date
Definition Returns a date result from a given aggregate SQL expression
Example
RAWSQLAGG_DATE("MAX(%1)", [Order Date])

In this example, %1 is equal to [Order Date].

RAWSQL_DATETIME

Syntax RAWSQL_DATETIME("sql_expr", [arg1], …[argN])
Output Datetime
Definition Returns a datetime result from a given SQL expression.
Example
RAWSQL_DATETIME("%1", [Order Date])

In this example, %1 is equal to [Order Date].

RAWSQLAGG_DATETIME

Syntax RAWSQLAGG_DATETIME("sql_expr", [arg1], …[argN])
Output Datetime
Definition Returns a datetime result from a given aggregate SQL expression.
Example
RAWSQLAGG_DATETIME("MIN(%1)", [Order Date])

In this example, %1 is equal to [Order Date].

RAWSQL_INT

Syntax RAWSQL_INT("sql_expr", [arg1], …[argN])
Output Integer
Definition Returns an integer result from a given SQL expression.
Example
RAWSQL_INT("500 + %1", [Sales])

In this example, %1 is equal to [Sales].

RAWSQLAGG_INT

Syntax RAWSQLAGG_INT("sql_expr", [arg1,] …[argN])
Output Integer
Definition Returns an integer result from a given aggregate SQL expression.
Example
RAWSQLAGG_INT("500 + SUM(%1)", [Sales])

In this example, %1 is equal to [Sales].

RAWSQL_REAL

Syntax RAWSQL_REAL("sql_expr", [arg1], …[argN])
Output Numeric
Definition Returns a numeric result from a given SQL expression.
Example
RAWSQL_REAL("-123.98 * %1", [Sales])

In this example, %1 is equal to [Sales]

RAWSQLAGG_REAL

Syntax RAWSQLAGG_REAL("sql_expr", [arg1,] …[argN])
Output Numeric
Definition Returns a numeric result from a given aggregate SQL expression.
Example
RAWSQLAGG_REAL("SUM( %1)", [Sales])

In this example, %1 is equal to [Sales].

RAWSQL_SPATIAL

Syntax RAWSQL_SPATIAL("sql_expr", [arg1], …[argN])
Output Spatial
Definition Returns a spatial result from a given SQL expression.
Example
RAWSQL_SPATIAL("%1", [Geometry])

In this example, %1 is equal to [Geometry].

Note There is no RAWSQLAGG version of this function.

RAWSQL_STR

Syntax RAWSQL_STR("sql_expr", [arg1], …[argN])
Output String
Definition Returns a string from a given SQL expression.
Example
RAWSQL_STR("%1", [Customer Name])

In this example, %1 is equal to [Customer Name].

RAWSQLAGG_STR

Syntax RAWSQLAGG_STR("sql_expr", [arg1,] …[argN])
Output String
Definition Returns a string from a given aggregate SQL expression.
Example
RAWSQLAGG_STR("AVG(%1)", [Discount])

In this example, %1 is equal to [Discount].

Thanks for your feedback!Your feedback has been successfully submitted. Thank you!