boolean wertdarstellung einstellen

Hallo,

wo, bzw. wie ist denn einzustellen das

create table test ( bv boolean);
insert into test values (true);
insert into test values (false);
select * from test;

nicht ein Ergebnis in Form von t und f liefert, sondern 1 und 0?
Laut doc sind das ja gültige Repräsentationen für Boolsche Werte…

Vielen Dank im Voraus, Grüße
beho



test=# create table b (id int, b bool);
CREATE TABLE
test=*# insert into b values (1, 'true'::bool);
INSERT 0 1
test=*# insert into b values (2, 'false'::bool);
INSERT 0 1
test=*# select id, case when b then '1' else '0' end from b;
 id | case
----+------
  1 | 1
  2 | 0
(2 rows)

Andreas

dankeschön!! Das Select CASE war das Entscheidende. Allerdings stellt sich die Frage, ob die Repräsentation von True und False auch standardmäßig als 1 bzw. 0 einstellbar ist.

Viele Grüße
beho

anders gefragt, denn das würde mir auch helfen, kann ich bzw. wie kann ich eine Typenumwandlung der BOOLEAN SPALTE in BIT vornehmen?

ALTER TABLE test ALTER COLUM bv TYPE BIT;

gibt ERROR: column “bv” cannot be cast to type “pg_catalog.bit” SQL Status:42804 aus…

Für Hilfe wär ich nochma echt dankbar
beho



test=# \d b
       Table "public.b"
 Column |  Type   | Modifiers
--------+---------+-----------
 id     | integer |
 b      | boolean |

test=# alter table b alter column b type bit(1) using case when b then 1::bit(1) else 0::bit(1) end;
ALTER TABLE
test=*# \d b
       Table "public.b"
 Column |  Type   | Modifiers
--------+---------+-----------
 id     | integer |
 b      | bit(1)  |

Andreas

Ah ok, danke! Soweit war ich fast… Hast du eventl. noch zwei drei Worte bezgl. 1::bit(1)? mir is die Notwendigkeit des ::-Operators nicht so wirklich klar.

Grüße
beho

Das ist ein CAST-Operator, die :: - Schreibweise ist PG-only, Standard wäre cast(…), siehe auch Doku.

Andreas