sql - PostgreSQL creating enum of enums -
i'm wondering if there way create enum of enums in postgresql example:
animation enum of ('stop-motion', 'cgi', 'motion-capture')
and
moviegenre enum of (animation, 'fantasy', 'sci-fi', 'horror')
so method can insert like:
insert movies (name, genre) values ('dawn of planets of apes', 'motion-capture'), ('annabelle', 'horror')`
and can have queries
select * movies genre animation
the ltree
info type way forward, see documentation here. ltree
info type elegant hierarchical construction label-type info in case. label paths be:
animation animation.stop-motion animation.cgi animation.motion-capture phantasy sci-fi horror
and corresponding insert
statement:
insert movies (name, genre) values ('dawn of planets of apes', 'animation.motion-capture'), ('annabelle', 'horror');
and select
statement:
select * movies genre <@ 'animation';
this select
statement homecoming records of 3 animation types.
note ltree
extension superuser has create extension ltree;
if (s)he hasn't done other purposes.
sql postgresql enums
No comments:
Post a Comment