> Heiko Schlittermann <[email protected]> hat am 23. Juli 2014 um 23:32
> geschrieben:
>
>
> Hallo,
>
> ich bin gerade irgendwie nicht in der Lage, in PostgreSQL etwa folgendes
> zu haben:
>
>         
>     Ein Objekt kann beschrieben werden durch eine Reihe von Attributen
>         
>         Name    ist Text
>         Size    ist ein Integer
>         Colors  ist ein Set von Werten aus dem Bereich 'red', 'green', 'blue'
>
>
>     Also:
>
>        Name|Sz.|Colors
>     -------+---+--------
>         Foo|12 |red
>         Bar|10 |red,blue
>         Baz|7  |green
>         Baf|42 |green,blue
>
>
>        CREATE TYPE colors AS ENUM ('red', 'green', 'blue');
>     -- so stelle ich mir das vor: CREATE TYPE colors AS SET ('red', 'green',
>'blue');
>
>     Aber so geht das nicht. Wie dann?
>     MySQL kann doch Mengen, oder?
>


Mir scheint, Du suchst sowas wie:

test=# create type colors as enum ('red','green', 'blue');
CREATE TYPE
test=*# create table foobar (id int, color colors[]);
CREATE TABLE
test=*# insert into foobar values (1, array['red'::colors, 'blue'::colors]);
INSERT 0 1
test=*# select * from foobar;
 id |   color
----+------------
  1 | {red,blue}
(1 row)
test=*# select id, array_to_string(color,',') as color from foobar;
 id |  color
----+----------
  1 | red,blue
(1 row)



Also, erst einmal den Typ als ENUM und davon dann ein ARRAY.

Warum magst Du keine normalisierte Speicherung hier?

_______________________________________________
Lug-dd maillist  -  [email protected]
https://ssl.schlittermann.de/mailman/listinfo/lug-dd

Antwort per Email an