HogQL guide

Last updated:

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:

SQL
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:

SQL
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.

Questions?

Was this page useful?

Next article

Supported ClickHouse functions

The following ClickHouse functions are enabled. This list is ever expanding . Please submit a pull request if we're missing something obvious. Type conversion toInt toFloat toDecimal toDate toDateTime toUUID toString toJSONString parseDateTime parseDateTimeBestEffort Arithmetic plus minus multiply divide intDiv intDivOrZero modulo moduloOrZero positiveModulo negate abs gcd lcm max2 min2 multiplyDecimal divideDecimal Arrays and strings in common empty notEmpty length reverse in notIn Arrays…

Read next article