Profile Query Language (PQL) is an Experience Data Model (XDM) compliant query language which is designed to support the definition and execution of segmentation queries for Real-Time Customer Profile data.
This guide provides a general overview of PQL, covering formatting guidelines and providing example PQL expressions.
PQL queries have the following signature:
({INPUT_PARAMETER_1}, {INPUT_PARAMETER_2}, ...) => {RESULT_TYPE}
The input parameter can be a simple primitive, such as a boolean or a string, or a more complex type, such as an object, array, or map.
There are three different ways to refer to input parameters within the body of a PQL expression:
In the example below, since the first parameter is always in context, a property reference (homeAddress
) can be made directly to it.
homeAddress.stateProvince = workAddress.stateProvince
In the example below, $1
refers to the first parameter. As a result, $2
would refer to the second parameter, etc.
$1.homeAddress.stateProvince = $1.homeAddress.stateProvince
In the example below, Profile
is a variable name, which can be chosen by the query author.
(Profile) => Profile.homeAddress.stateProvince = Profile.workAddress.stateProvince
PQL provides support for the following literal types:
Literal | Definition | Example |
---|---|---|
String | A data type comprised of characters surrounded by double quotes. | "pizza" , "jobs" , "antidisestablishmentarianism" |
Boolean | A data type that is either true or false. | true , false |
Integer | A data type representing a whole number. It can be positive, negative, or zero. | -201 , 0 , 412 |
Double | A data type representing any real number. It can be positive, negative, or zero. | -51.24 , 3.14 , 0.6942058 |
Date | A data type that can be used to create dates based on the year, month, and day as integer parameters. It is formatted as date(year, month, day) |
date(2020, 3, 14) |
Array | A data type that is comprised as a group of other literal values. It uses square brackets to group and commas to delimit between different values. Note: You cannot directly access properties of items within an array. So, if you need to access a property within an array, the supported method is select X from array where X.item = ... . PQL reserves the word xEvent to refer to an array of experience events linked to a profile. |
[1, 4, 7] , ["US", "CA"] |
Relative time references | Reserved words that can be used to form timestamp and time interval references.
|
X.timestamp occurs before today , X.timestamp occurs last month , X.timestamp occurs <= 3 days before now |
The following table outlines the different categories of supported PQL functions, including links to further documentation for more information.
Category | Definition |
---|---|
Boolean | Used to implement boolean algebra within PQL. More information about these functions can be found in the boolean functions document. |
Comparison | Used to compare between different PQL elements. More information about these functions can be found in the comparison functions document. |
Array, list, and set | Used to interact with arrays, lists, and sets. More information about these functions can be found in the array, list, and set functions document. |
Map | Used to interact with maps. More information about these functions can be found in the map functions document. |
String | Used to interact with strings. More information about these functions can be found in the string functions document. |
Object | Used to interact with objects. More information about these functions can be found in the object functions document. |
Arithmetic | Used to perform basic arithmetic on PQL elements. More information about these functions can be found in the arithmetic functions document |
Aggregation | Used to combine results of an array into a singular result. More information about aggregation functions can be found in the aggregation functions document. |
Date and time | Used in conjunction with date, time, and datetime objects. More information about these functions can be found in the date/time functions document. |
Filter | Ued to filter data within arrays. More information about these functions can be found in the filter functions document. |
Logical quantifiers | Used to assert conditions within an array. More information can be found in the logical quantifiers document. |
Miscellaneous | Functions that do not fit in any of the above categories can be found in the miscellaneous functions document. |
Now that you’ve learned how to use Profile Query Language, you can use PQL when creating and modifying segment definitions. For more information on segmentation, please read the segmentation overview.