Postgres Naming Trigger

2021-02-02 :: ( 1 minutes reading )

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();
comments powered by Disqus

Archives

English

  • My Desktop With i3, polybar, conky, and rofi
  • Convert Intellij Live Template to vscode Snippet
  • Why for-range behaves differently depending on the size of the element (A peek into go compiler optimization)
  • Testing go 1.5 cross compilation on raspberry pi
  • osx-push-to-talk App
  • Tracking origin of bugs with git bisect
  • Stubbing Time.Now() in golang
  • My account just got hacked by Romanian (Possibly)
  • berks upload core dump
  • Safely sharing credentials with PGP

Indonesia

  • Ruby Fiber apaan sih ?
  • Scale MongoDB dengan Sharding
  • Telepon murah ke Indonesia dengan voip

Today I Learned

  • Postgres Naming Trigger
  • Postgres Audit Log Trigger
  • Intellij as git diff and mergetool
  • Checksum a File From a URL
  • Global Gitignore File
  • View kubernetes secret
  • Push Only Current Branch
  • Convert PDF to Text Using OCR
  • Checkout Last Branch
  • Replacing Last Command and Execute It
Labs.Yulrizka.com
twitter github feed
    • Left Panel
    • No Panel
    • Right Panel
  • Home
  • EN
  • ID
  • Today I Learned

© Ahmy Yulrizka 2019. Made with hugo source