Skip to content

TAGS

Apply subsequent annotations only when the endpoint has specific tags.

Overview

Tags are automatically assigned to endpoints by different routine sources (functions, procedures, tables, views). The for/tags annotation allows you to conditionally apply annotations based on these tags.

This is useful for:

  • Applying different configurations based on routine volatility (volatile, stable, immutable)
  • Customizing behavior for CRUD operations (select, insert, update, delete)
  • Environment-specific settings when combined with custom tags

Keywords

for, tags, tag

Syntax

for <tag1> [tag2] [tag3] ...
tags <tag1> [tag2] [tag3] ...

Annotations following the for/tags line apply only when the endpoint has at least one of the specified tags.

Automatic Tags by Source

Function or Procedure Source

Tags are assigned based on routine volatility:

TagDescription
volatileFunctions declared as VOLATILE
stableFunctions declared as STABLE
immutableFunctions declared as IMMUTABLE
otherProcedures and other routines

Table or View CRUD Source

Different CRUD operations receive different tags:

OperationTags
Selectselect, read, get
Insertinsert, put, create
Insert On Conflict Do Nothinginsert, put, create, insert_on_conflict_do_nothing, on_conflict_do_nothing, on_conflict
Insert On Conflict Do Nothing Returninginsert, put, create, insert_on_conflict_do_nothing_returning, on_conflict_do_nothing, on_conflict, returning
Insert On Conflict Do Updateinsert, put, create, insert_on_conflict_do_update, on_conflict, on_conflict_do_update
Insert On Conflict Do Update Returninginsert, put, create, insert_on_conflict_do_update_returning, on_conflict_do_update, on_conflict, returning
Update Returningupdate, post, update_returning, returning
Deletedelete
Delete Returningdelete, delete_returning, returning

Examples

Volatility-Based Configuration

sql
-- Apply caching only to immutable functions
comment on function calculate_hash(_data text) is
'HTTP GET
for immutable
cached';

CRUD-Specific Authorization

sql
-- On a table, require authorization only for write operations
comment on table products is
'for select
allow_anonymous
for insert update delete
authorize admin';

Environment-Specific Authorization

sql
comment on function sensitive_data() is
'HTTP GET
for production
authorize admin
for development
allow_anonymous';

Tag-Specific Paths

sql
comment on function get_users() is
'HTTP GET
for v1
path /api/v1/users
for v2
path /api/v2/users';

Multiple Tags

sql
-- Apply rate limiting to all volatile operations
comment on function api_call() is
'HTTP POST
for volatile insert update delete
rate_limiter_policy strict';

Behavior

  • Annotations after for/tags apply until the next for/tags line or end of comment
  • If an endpoint matches any of the specified tags, the annotations are applied
  • Tags are case-insensitive
  • Multiple for/tags blocks can be used in the same comment
  • Custom tags can be defined in addition to automatic tags

Released under the MIT License.