SQL vs SAQL
SQL for CRM Analytics and Salesforce Analytics Query Language (SAQL) are both query languages intended for use with CRM Analytics. Here’s a guide to their different behaviors and limitations.
You can only write SQL queries against datasets.
SQL for CRM Analytics doesn’t offer support for these features available in SAQL.
- Random sampling
- Cogrouping
- SAQL functions
string_to_number()andtoString(). Type casting is unavailable in SQL for CRM Analytics. - Relative date filtering, for example,
Closed_Datein["2 years ago".."1 day ago"] - Date functions such as
day_in_week(),date_diff(),now(),date_to_epoch(), anddate_to_string()tc
SQL and SAQL have the following differences in behavior.
-
In a grouped query, SQL returns a group for null values in a grouped query by default.
-
In SQL, counting all records in an empty dataset returns 0. In SAQL, it returns an empty response.
-
In SQL, the
GROUPING()function can take multiple arguments. In SAQL, it takes one argument only. -
SAQL’s
DateOnlytype corresponds with SQL for CRM Analytics’sDatetype. -
SAQL’s
DateTimeandDatetypes correspond with SQL’sTimestamptype. -
In SQL, the
DateandTimestamptypes are treated as dates. In SAQL, when timezone is enabled, theDateOnlyandDateTimetypes are treated as dates. When timezone isn’t enabled, theDateOnlyandDateTimetypes are treated as strings. -
When columns in a
SELECTstatement have the same data types, but different aliases,UNION ALLin SQL returns the results in a single column. In SAQL,unionreturns all of the columns. -
If your values query (one without a grouping) includes aggregated and non-aggregated fields, SQL throws an error. SAQL handles such queries differently by taking the value of individual rows.
In this example,
Cityis a non-aggregated field.Countandsum_Profitare aggregated fields.This SQL query throws an error.
The corresponding SAQL query yields the sum of
Profitfor eachCity.