select is a method for specifying which fields to query. You can select fields in a type-safe manner and use SQL aggregate functions and expressions.
Basic Usage
Query All Fields
Select Specific Fields
Field Alias
SQL Aggregate Functions
Puri provides type-safe SQL functions.COUNT
SUM, AVG, MAX, MIN
String Functions
Puri.concatExpressions() adds PostgreSQL text casts to bound literal parameters, so
literal-only expressions like the example above are runnable. Legacy Puri.concat() binds
literals as untyped parameters and does not treat column-like strings as columns. A standalone
literal-only Puri.concat() expression is therefore not runnable on PostgreSQL. Use
Puri.concatExpressions() to combine string SQL expressions with literal text.
Raw SQL Expressions
You can use complex SQL expressions.Type-Specific Raw Functions
Nested Object Selection
You can write SELECT statements with nested object structures.appendSelect
Adds fields to existing SELECT.Full-Text Search Functions
ts_highlight (PostgreSQL)
Highlighting using PostgreSQLβs tsvector.parser: Query parser (default:"websearch_to_tsquery")config: Text search configuration (default:"simple")startSel: Start tag (default:"<b>")stopSel: End tag (default:"</b>")maxWords: Maximum number of wordsminWords: Minimum number of wordsmaxFragments: Maximum number of fragments
ts_rank (PostgreSQL)
Calculates search relevance score.parser: Query parser (default:"websearch_to_tsquery")config: Text search configuration (default:"simple")weights: [D, C, B, A] weight arraynormalization: Normalization option (0-32)
PGroonga Functions
Full-text search using PGroonga extension.pg_trgm Similarity Functions
Calculates similarity scores provided by PostgreSQLβspg_trgm extension in SELECT. After filtering candidates with whereFuzzy, these functions can be used to compute per-column weighted scores.
SqlExpression<"number">. These expressions can be combined with rawNumber to compute
per-column weighted scores.
The result preserves the input expressionβs nullability.
jsonText() produces a nullable string
expression; passing it to a similarity helper produces SqlExpression<"number", true> and selects as number | null; a plain
column or non-null expression produces SqlExpression<"number"> and selects as number. The
pg_trgm extension must be installed.Practical Examples
- User Statistics
- Order Summary
- Users + Posts
- Search + Highlighting
Type Safety
SELECT return types are automatically inferred.Cautions
1. select vs appendSelect
2. Table Prefix Required
3. Specify Raw SQL Types
Next Steps
where
Filter with conditions
join
Join tables
order-by
Sort results
advanced-methods
Advanced query methods