Strings and quotes
Quotation symbols work the same way they would work with ClickHouse, which inherits from ANSI SQL:
- Single quotes (
'
) for Strings literals. - Double quotes (
"
) and Backticks (`) for DataBase identifiers.
For example:
SELECT * FROM events WHERE properties.`$browser` = 'Chrome'
Property access
To access a property stored on an event or person, just use dot notation. For example properties.$browser
or person.properties.$initial_browser
.
Nested property or JSON access, such as properties.$some.nested.property
, works as well.
PostHog's properties include always include
$
as a prefix, while custom properties do not (unless you add it).
Property identifiers must be known at query time. For dynamic access, use the JSON manipulation functions from below on the properties
field directly.
Property types
If you have specified a type for an event or person property under "Data Management", it will be returned in this type. All other properties are returned as strings.
For example:
SELECT round(properties.$screen_width * properties.$screen_height / 1000000, 2) as `Screen MegaPixels` FROM events LIMIT 100
This works because $screen_width
and $screen_height
are both defined as numeric properties. Thus you can multiply them.
To cast a string property into a different type, use type conversion functions, such as toFloat()
.
You can find a full list of properties and their types in your data management tab.