Skip to main content
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.
select() overwrites existing SELECT, while appendSelect() appends to it.

Full-Text Search Functions

ts_highlight (PostgreSQL)

Highlighting using PostgreSQL’s tsvector.
Options:
  • 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 words
  • minWords: Minimum number of words
  • maxFragments: Maximum number of fragments

ts_rank (PostgreSQL)

Calculates search relevance score.
Options:
  • parser: Query parser (default: "websearch_to_tsquery")
  • config: Text search configuration (default: "simple")
  • weights: [D, C, B, A] weight array
  • normalization: Normalization option (0-32)

PGroonga Functions

Full-text search using PGroonga extension.

pg_trgm Similarity Functions

Calculates similarity scores provided by PostgreSQL’s pg_trgm extension in SELECT. After filtering candidates with whereFuzzy, these functions can be used to compute per-column weighted scores.
Weighted score example: For a plain column or non-null string expression, similarity functions return SqlExpression<"number">. These expressions can be combined with rawNumber to compute per-column weighted scores.
Function comparison:
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

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