> For the complete documentation index, see [llms.txt](https://til.yulrizka.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.yulrizka.com/db/postgres-naming-trigger.md).

# postgres naming trigger

Taken From <https://severalnines.com/database-blog/postgresql-triggers-and-stored-function-basics>

Pattern `[TBALE_NAME]_[FUNCITON NAME]_[WHEN][1 or more WHY][t]`

When:

* b - Before
* a - After
* i - Instead of

WHY:

* i - Insert
* u - Update
* d - Delete
* t - Truncate

t = 'trigger'

eg: `my_table_update_ts_biut` means it's a trigger on my\_table, triggers update\_ts before insert & update

Reasoning: Just by looking at the trigger name, you know which table, and when it is triggered

example

```
-- function to update updated_at column during insert or update
CREATE OR REPLACE FUNCTION update_timestamp()
    RETURNS trigger AS
$$
BEGIN
    NEW.updated_at := NOW();
    RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';


CREATE TRIGGER users_update_timestamp_biut
    BEFORE INSERT OR UPDATE
    ON users
    FOR EACH ROW
EXECUTE PROCEDURE update_timestamp();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.yulrizka.com/db/postgres-naming-trigger.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
