Use operators and expressions in queries
mainQueries are written in a Lisp-style prefix notation. If a symbol looks like an operator, EmacSQL treats it as one.
Special Operators:
- Range:
<=and>=accept 2 or 3 operands and transform into SQLBETWEENlogic. - Function calls: Use the
funcalloperator for SQL functions likecountormax. - Concatenation: The
||operator is unsupported to ensure all values remain readable within SQLite.
Important Note on Quoting:
- Identifiers vs Values: EmacSQL cannot distinguish between a symbol used as a column name and a symbol used as a value. To use a symbol as a value, you must quote it (e.g.,
'hiking). - Raw Strings: Quoting a string (e.g.,
"%foo%") makes it a "raw string" that is not printed/escaped. Use this forLIKEpatterns orATTACHcommands.
;; Using funcall for aggregate functions
[:select (funcall max age) :from people]
;; Quoting a symbol to treat it as a value
(emacsql db [... :where (= category 'hiking)])
;; Using raw strings for pattern matching
(emacsql db [... :where (like name '"%foo%")])