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

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: The return values of similarity functions (SqlExpression<"number">) can be combined with rawNumber to compute per-column weighted scores.
Function comparison:
These functions return SqlExpression<"number"> and can be used within select. 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