pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: lucas@presserv.org
To: pgsql-sql@postgresql.org
Subject: Default on update
Date: Wed, 23 Nov 2005 08:43:53 -0300
Message-ID: <20051123084353.8ga6nrpx43gg8408@www.presserv.org> (raw)

Hi.
Is there a way to create "default" constraint on UPDATE query.
It's becouse I have a bool field that may NOT support NULL value, but the
Front-End calls null for FALSE values.
I was thinking something like:
 create table table1 (
  id serial primary key,
  bv bool default false not null
 );
I would want to replace "bv" values with FALSE when insert/update NULL value for
this field.
Or need I create a TRIGGER that check it and replace the itens???
CREATE or REPLACE function TG_table1_check RETURNS trigger as '
 BEGIN
  IF nullvalue(NEW.bv) THEN
   NEW.bv=FALSE;
  END IF;
 END;
' language 'plpgsql'; CREATE TRIGGER TG_table1_check BEFORE UPDATE on table1 for
each row execute procedure tg_table1_check();

Other question: I have a lot of triggers in my db system, I have table that has
5/6 triggers, many triggers are simple (like the tg_table1_check), any are
complex... Is it a problem??? My tests are with few regs and run fine. Where
can I read more about triggers and performance?

Thanks for all.
---
Lucas Vendramin



view thread (4+ messages)  latest in thread

Message-ID: <20051123084353.8ga6nrpx43gg8408@www.presserv.org>
Permalink:  ../20051123084353.8ga6nrpx43gg8408@www.presserv.org/
Also on:    postgresql.org/message-id/20051123084353.8ga6nrpx43gg8408@www.presserv.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: lucas@presserv.org
  Subject: Re: Default on update
  In-Reply-To: <20051123084353.8ga6nrpx43gg8408@www.presserv.org>
  References: <20051123084353.8ga6nrpx43gg8408@www.presserv.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox