I have two tables. I want to create a trigger on the car table which will insert or delete on the fuel table depending on a certain value.
Car
id - SERIAL
fuel - BOOLEAN
Fuel
car_id - INTEGER
I am not including any row data as the description of the trigger does not need it.
Basically, I want to create a trigger on the Car table that:
- Runs on an insert or update.
- Inserts
Car.idintoFueltable ifCar.fuel is true. - If
Car.fuel is false, the trigger should delete all rows in theFueltable whereFuel.car_id = Car.id.
How would I do this?
EDIT: To clarify I am using Postgres
psqlis mostly short for Postgres, that's true. But it could also be a typo meaningPL/PSQL(which is Oracle's procedural language). Postgres' procedural language is calledPL/pgSQL