1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[729],{729:(e,n,r)=>{r.r(n),r.d(n,{markdown:()=>t});let t="# Booking Ref Default Conflicts with Trigger\n\nThe `bookings.ref` column has `DEFAULT generate_ref()`, but there is also a `booking_ref_trigger` (BEFORE INSERT) whose retry loop is supposed to handle collisions.\n\n## Problem\n\nPostgreSQL applies column defaults before BEFORE triggers run. By the time the trigger fires, `NEW.ref` is already set by the DEFAULT, so the trigger's `IF NEW.ref IS NOT NULL THEN RETURN NEW` branch always exits immediately â the retry loop never executes.\n\nThis means a collision on the DEFAULT-generated value surfaces as a unique constraint violation error instead of being retried transparently.\n\n## Fix\n\nRemove the `DEFAULT generate_ref()` from the column so the trigger is the sole mechanism for both generation and collision retry:\n\n```sql\nALTER TABLE bookings ALTER COLUMN ref DROP DEFAULT;\n```\n\nWith the DEFAULT gone, `NEW.ref` is NULL on insert, the trigger loop runs, and collisions are retried silently.\n\n## Impact\n\nLow urgency â with 36^5 (~60M) possible refs, collisions are extremely unlikely at current scale. But the trigger gives a false sense of safety while doing nothing.\n"}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.