SQL API conventions
This companion describes SQL 0.1.1, from source commit cbff27b8a34e1384384018680e46c20d5c610cc9. The function reference contains catalog-derived signatures, defaults, and return shapes alongside reviewed behavior.
All public functions live in the fixed postgremq schema. Call them with schema qualification. The trigger function that distributes publications is an internal implementation detail, not an application entry point.
Transactions and privileges
SQL functions participate in the caller's transaction. A returned message ID, successful acknowledgement, or deletion is provisional until that transaction commits. Rollback undoes its database changes. Locks remain held until transaction end; keep transactions short.
Most functions use caller privileges, including access to their underlying tables and sequence. info() is the security-definer exception that reports discovery information without runtime access to migration tracking. See Roles and permissions.
Read-only listing and metrics functions do not reserve deliveries. Use consume_message to obtain an ownership token before settlement. Do not infer ownership from a row returned by list_messages or edit internal tables to simulate a claim.
Arguments, units, and names
| Argument family | Convention |
|---|---|
| Topic and queue names | Nonempty ASCII letters, digits, underscore, colon, period, and hyphen; at most 57 bytes. |
| Group key | Optional text, up to 255 characters; empty string rejected. |
| Message ID | PostgreSQL BIGINT; identify a publication, not its claim owner. |
| Visibility timeout | Integer seconds from the database clock. |
| Publication or retry time | Absolute TIMESTAMPTZ. |
| Queue lifetime | Interval for declaration; integer milliseconds in batch renewal. |
| Retention age | Integer hours. |
| Batch size | Maximum selected rows for that operation, not a transaction-duration limit. |
Database timing uses the function's documented clock. Eligibility is not a scheduled-execution guarantee. The server stores queue state; notifications only prompt clients to inspect it.
Omitted arguments are not explicit NULL
Defaults apply when an argument is omitted. Explicit NULL can have different and sometimes unsafe behavior. Use concrete non-null values unless the function explicitly defines NULL as meaningful.
publish_message accepts NULL delivery time as now and NULL group key as ungrouped. A NULL generation means no incarnation constraint. get_queue_statistics(NULL) aggregates all queues. These are intentional cases.
A NULL claim or cleanup batch limit removes that limit. NULL retention age selects no eligible rows. extend_queue_keep_alive_multi(NULL, NULL) raises 22004 because it cannot construct an array with a null dimension. Other NULLs can produce a missing-target error, a constraint violation, an omitted batch result, or a no-op. See the individual function and Errors; do not generalize one function's validation to the whole API.
Results and ownership
A queue generation identifies its incarnation. Reusing a name after deletion creates a different generation. Pass the expected generation when a custom client must reject silent replacement.
A delivery token identifies one processing claim. Settlement uses queue name, message ID, and token together. Batch extension results must be correlated by all three, not message ID alone. An omitted batch result means ownership is not confirmed for that entry; a busy result means the row was locked and requires a later retry within the last confirmed deadline.
Read Using PostgreMQ through SQL for a first claim-and-acknowledge walkthrough and Notifications and polling before implementing a custom client.