DATUI-QUERY(7) Miscellaneous DATUI-QUERY(7)

datui-query - the q syntax of the datui command line

select [columns] [by groups] [where conditions]

Each part optional
In where, , is and; | is or
Aggregate by group
Name a column; a name with spaces
1/c+a is 1/(c+a)
Right to left: 100 < (a+b)*2
Accessors and dates
Membership and patterns

The grammar of q on the command line (:, then q:): a subset of the q language, evaluated right to left. Query data walks through it. Every example below runs on the public dataset its block names; open that dataset from Example datasets on the home screen.

q and kdb+ are trademarks of KX Systems. datui is not affiliated with or endorsed by KX.

Each part in brackets is optional; replace it with a list of expressions:

select [columns] [by group_columns] [where conditions]
Required. Alone it means all columns; otherwise a comma-separated list of column expressions
Optional. Grouping and aggregation
Optional. The table on screen, as in q and like SQL's FROM df; no other name
Optional. Filtering

Use clauses in the order shown, at most once each. Misplaced or repeated clauses and extra tokens after an expression are errors.

name : expression names an expression. The left side is the new column or group name, an identifier (total) or col["name with spaces"]; the right side is any expression (column reference, literal, arithmetic, function call).

On the flights dataset (see DATASETS):

select carrier, flight, gain: dep_delay - arr_delay
select route: dest, flight
select flights: count flight by airline: carrier, long: distance > 1000

Assignment works in both select and by. In by it defines computed group keys or renames.

Identifiers cannot contain spaces. For columns (or aliases) with spaces, use col["..."] with a quoted string, or col[identifier] for a name without spaces. The same syntax works in select, by and where.

On the football dataset (see DATASETS):

select col["Team 1"], col["Team 2"], FT
select home: col["Team 1"]

A column named like a function (count, log, var) is read as the function when something follows it, so select log + 1 is log(+1). Write col["log"] + 1.

There is no operator precedence. Expressions are parsed right-to-left: the leftmost binary operator is the root, and everything to its right is parsed first as a unit.

Put the operation you want done first on the right, or use () to override grouping:

On the flights dataset (see DATASETS):

select gain: (dep_delay - arr_delay) * 60
select carrier, flight where (dep_delay > 60) | (arr_delay > 60)

Parentheses also matter for , and | in where: splitting on comma and pipe respects nesting, so you can wrap ORs in () and combine them with commas. See Where clause.

By uses the same comma-separated list and name : expression rules as select. Aggregation functions (avg, min, max, count, sum, std, med, nunique, var, dev) can be written fn[expr] or fn expr; brackets are optional. wavg goes between its operands: w wavg x.

An unaliased aggregate of a single column is named {fn}_{column}, so select avg dep_delay, max dep_delay by carrier yields avg_dep_delay and max_dep_delay; an explicit alias (total: sum[distance]) overrides it.

The where clause combines conditions with two separators:

The where part is split on , first (respecting () and []), then each segment on |, so , has broader scope than |:

(a > 10) AND (b < 2)
(a > 10) OR (a < 5)
(a > 10 OR a < 5) AND (b = 2)
A AND (B OR C)
(A OR B) AND (C OR D)

The where clause takes conditions only: no name: expression assignment.

For more complex logic, wrap OR subexpressions in () — parentheses keep | inside one AND term — and separate the groups with ,.

+ - * / % (/ and % both divide; % is not modulo, mod is)
=, !=, <> (same as !=)
< > <= >=
^ — first non-null, left to right; a^b^c = coalesce(a, b, c), binding right-to-left as a^(b^c)
42, 3.14
"hello", \" for an embedded quote
2021.01.01 (YYYY.MM.DD)
2021.01.15T14:30:00.123456 (YYYY.MM.DDTHH:MM:SS[.fff...]); fractional-second digits set precision: 1–3 = ms, 4–6 = μs, 7–9 = ns

A timestamp literal compared with a column that has a time zone is read as a clock time in that zone. A clock time repeated when clocks fall back means its first instant.

Quoted text is a string, never a date: where d = "2024.01.01" on a date column is an error that names the literal to write, here 2024.01.01. Time and duration columns have no literal; compare t.hour, t.minute or t.second with a number.

Either side of a comparison can be a column, a literal or an expression: where a = 10, where created_at.date > other_date_col.

q's infix words, parsed right-to-left like every other operator.

Result: True where x equals one of the values; the right side is a bracketed list
Example: select total: sum n by name where name in ["Emma", "Jennifer", "Olivia"]
Result: True where the whole value matches: * is any run of characters, ? one character; case-sensitive
Example: select restaurant, item where item like "*Chicken*"
Result: x rounded down to a multiple of size, for buckets; a whole-number size keeps integers integral
Example: select trips: count fare_amount by b: 5 xbar fare_amount
Result: Remainder, with the sign of n (-7 mod 3 is 2)
Example: select dep_time, minute: dep_time mod 100
Result: Average of x weighted by w, an aggregate; pairs where either is null are skipped
Example: select delay: distance wavg arr_delay by carrier

Because evaluation is right-to-left, x mod 2 in [1] is x mod (2 in [1]). Write (x mod 2) in [1] or 1 = x mod 2. not name in ["Mary"] negates the whole test.

The words are operators only between two operands. A column named in or mod still works on its own or at the start of an expression, and col["in"] always does.

For columns of type Date or Datetime (with or without timezone), dot notation extracts components: column_ref.accessor.

Date part (year-month-day); Datetime only
Result: Date
Time part (Polars Time type); Datetime only
Result: Time
Year
Result: Int32
Month (1–12)
Result: Int8
Week number
Result: Int8
Quarter (1–4)
Result: Int8
Day of month (1–31)
Result: Int8
Day of year (1–366)
Result: Int16
Day of week (1=Monday … 7=Sunday, ISO)
Result: Int8
Hour (0–23); Datetime and Time
Result: Int8
Minute (0–59); Datetime and Time
Result: Int8
Second (0–59); Datetime and Time
Result: Int8
First day of month, at midnight for Datetime
Result: Date/Datetime
Last day of month
Result: Date/Datetime
Format as string (chrono strftime, e.g. "%Y-%m")
Result: String

Apply to String columns:

Character length
Result: Int32
Uppercase
Result: String
Lowercase
Result: String
True if the string starts with x
Result: Boolean
True if the string ends with x
Result: Boolean
True if the string contains x
Result: Boolean
Split on sep and take piece n, counting from 0; negative counts from the end; past the last piece is null
Result: String
len characters from start (0-based; negative counts from the end); without len, to the end
Result: String
Every from replaced with to, literally
Result: String
Leading and trailing whitespace removed
Result: String
Parse with a chrono format such as "%Y%m%d"; without a format, Polars infers it
Result: Date
As to_date, for date and time: "%Y-%m-%d %H:%M"
Result: Datetime

part, slice, replace, strip, to_date and to_datetime also work on number and date columns, read as their text: NOAA's DATE parses whether it was read as 20240101 text or as an integer. A value that does not parse becomes null.

Round to n decimals, halves away from zero; round alone rounds to a whole number
Result: Number
Convert; text that is not a whole number becomes null
Result: Int64
Convert; text that is not a number becomes null
Result: Float64
Convert to text
Result: String

Accessors chain left to right: FT.part["–", 0].int. Arguments are literals, quoted text or numbers, and a wrong number of them is an error naming the accessor. To apply an accessor to an aggregate or an expression, wrap it in parentheses: (avg dep_delay).round[1].

An accessor result is automatically aliased to {column}_{accessor}, so timestamp.date becomes timestamp_date.

time_hour in NYC flights is a UTC datetime:

On the flights dataset (see DATASETS):

select day: time_hour.date
select time_hour.date, time_hour.year
select flight, time_hour.time
select time_hour, time_hour.month, time_hour.dow by time_hour.year
select delay: arr_delay^dep_delay
select tailnum.len, tailnum.upper, time_hour.format["%Y-%m"]
select where time_hour.date > 2013.06.30
select where time_hour.month = 12, time_hour.dow = 1
select where dest.ends_with["A"]
select where null dep_time
select where not null dep_time

tpep_pickup_datetime in NYC yellow taxis is a datetime with no time zone:

On the taxis dataset (see DATASETS):

select where tpep_pickup_datetime > 2025.01.15T14:30:00.123456

Functions are used for aggregation (typically in select with by) and for logic in where. Write fn[expr] or fn expr; brackets are optional.

Average
Aliases: mean
Example: select avg[dep_delay] by carrier
Minimum
Example: select min[dep_delay] by origin
Maximum
Example: select max[distance] by carrier
Count of non-null values
Example: select count[dep_time] by origin
Sum
Example: select sum[distance] by month
First value in group
Example: select first[dep_time] by day
Last value in group
Example: select last[dep_time] by day
Standard deviation (sample)
Aliases: stddev, dev
Example: select dev dep_delay by origin
Variance (sample)
Example: select var dep_delay by origin
Count of distinct values
Example: select planes: nunique tailnum by carrier
Weighted average, written w wavg x
Example: select delay: distance wavg arr_delay by carrier
Median
Aliases: median
Example: select med[air_time] by dest
String length (chars)
Aliases: length
Example: select len[tailnum]

Logical negation
Example: where not[origin = "JFK"], where not dep_delay > 10
Is null
Example: where null dep_time, where null[dep_time]
Is not null
Example: where not null dep_time

String length
Example: select len[tailnum], where len[tailnum] > 5
Uppercase string
Example: select upper[tailnum], where lower[origin] = "jfk"
Lowercase string
Example: select lower[carrier]
Absolute value
Example: select abs[dep_delay]
Numeric floor
Example: select floor[distance % 100]
Numeric ceiling
Example: select ceil[distance % 100]
Square root
Example: select sd: sqrt var dep_delay by origin
Natural logarithm
Example: select year, log_n: (log n).round[2] where name = "Emma"
e raised to the value
Example: select exp[1]

var, dev and std divide by n − 1, where q's var and dev divide by n.

NYC yellow taxis:

On the taxis dataset (see DATASETS):

select trips: count VendorID by tpep_pickup_datetime.hour
select trips: count fare_amount by b: 5 xbar fare_amount where fare_amount > 0, fare_amount < 100

Premier League:

On the football dataset (see DATASETS):

select home: FT.part["–", 0].int, away: FT.part["–", 1].int
select d: Date.replace["(P)", ""].strip.to_date["%a %b %d %Y"]
select matches: count Round by m: Date.replace["(P)", ""].strip.to_date["%a %b %d %Y"].month

US baby names:

On the names dataset (see DATASETS):

select total: sum n by name where name in ["Emma", "Jennifer", "Olivia"]
select total: sum n by decade: 10 xbar year where name = "Jennifer"
select year, log_n: (log n).round[2] where name = "Emma"

NYC flights:

On the flights dataset (see DATASETS):

select mean_delay: (avg dep_delay).round[1] by hour
select distinct carrier, origin
select planes: nunique tailnum by carrier
select delay: distance wavg arr_delay by carrier
select dep_time, minute: dep_time mod 100
select sd: sqrt var dep_delay by origin

Food nutrition:

On the food dataset (see DATASETS):

select items: count item by restaurant where item like "*Chicken*"
select restaurant, item where item like "*Chicken*"

Palmer penguins:

On the penguins dataset (see DATASETS):

select mean_mass_g: avg body_mass_g by species
select species, island, bill_ratio: (bill_length_mm % bill_depth_mm).round[2] where not null bill_length_mm

The examples run on the Example datasets that come with datui (on the home screen). Open one, press /, and type the query.

datui https://vincentarelbundock.github.io/Rdatasets/csv/nycflights13/flights.csv
    
datui https://raw.githubusercontent.com/footballcsv/england/de3945297668d7114006a8ca1c4c3740010b111c/2020s/2020-21/eng.1.csv
    
datui https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2025-01.parquet
    
datui https://raw.githubusercontent.com/rfordatascience/tidytuesday/8bfa9d9a7279192cb41cab041f426f2aacefde91/data/2022/2022-03-22/babynames.csv
    
datui https://vincentarelbundock.github.io/Rdatasets/csv/openintro/fastfood.csv
    
datui https://vincentarelbundock.github.io/Rdatasets/csv/palmerpenguins/penguins.csv
    

datui(1)

The datui documentation: <https://derekwisong.github.io/datui/>

Report bugs at <https://github.com/derekwisong/datui/issues>.

Derek Wisong and the datui contributors.

Copyright © 2026 Derek Wisong

datui is free software under the MIT License.

2026-10-06 datui 0.4.1