HogQL guide

Last updated:

|Edit this page

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.


Was this page useful?

Next article

HogQL expressions

HogQL expressions enable you to directly access, modify, and aggregate data in PostHog using SQL. You can use them nearly everywhere where event filters exist, including: Dashboards Data series Breakdowns Funnels Event explorer HogQL expressions can access data like: event properties person properties event elements_chain timestamp distinct_id person_id They then use SQL functions to access, filter, modify, or aggregate the data. A full list of SQL functions are found in our supported…

Read next article