Re: LibreOffice Base als Frontend - Problem mit boolean Feldern

Andreas Kretschmer <[email protected]> Fri, 25 Sep 2015 19:49:18 +0200
Newsgroups gmane.comp.db.postgresql.german
Message-ID <20150925174918.GA30328@tux>
Ulrich Goebel <[email protected]> wrote:

> Kann ich in der DB dafür sorgen, dass der Wert "unknown" in "FALSE"  
> verändert wird?
>
> Meine Idee: einen Trigger definieren. Aber wie?

So?

test=# create table bla(id int, b bool);
CREATE TABLE
Time: 0,925 ms
test=*# create or replace function set_false() returns trigger as
$$begin new.b := false; return new; end;$$language plpgsql;
CREATE FUNCTION
Time: 0,413 ms
test=*# create trigger trg1 before insert or update on bla for each row
when (new.b is null) execute procedure set_false();
CREATE TRIGGER
Time: 0,402 ms
test=*# insert into bla values (1, true);
INSERT 0 1
Time: 0,345 ms
test=*# insert into bla values (2, null);
INSERT 0 1
Time: 0,287 ms
test=*# insert into bla values (3, false);
INSERT 0 1
Time: 0,225 ms
test=*# select * from bla;
 id | b
----+---
  1 | t
  2 | f
  3 | f
(3 rows)





Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


-- 
Sent via pgsql-de-allgemein mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-de-allgemein