Profile Query Language (PQL) overview
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 query formatting
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:
Implicit reference to the first parameter
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
Explicit reference to the first parameter
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
Usage of named variables, using the lambda notation
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 literals
PQL provides support for the following literal types:
"pizza"
, "jobs"
, "antidisestablishmentarianism"
true
, false
-201
, 0
, 412
-51.24
, 3.14
, 0.6942058
date(year, month, day)
date(2020, 3, 14)
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"]
Reserved words that can be used to form timestamp and time interval references.
- now, today, yesterday, tomorrow
- this, last, next
- before, after, from
- millisecond(s), second(s), minute(s), hour(s), day(s), week(s), month(s), year(s), decade(s), century/centuries, millennium/millennia
X.timestamp occurs before today
, X.timestamp occurs last month
, X.timestamp occurs <= 3 days before now
PQL functions
The following table outlines the different categories of supported PQL functions, including links to further documentation for more information.
Next steps
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.