Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D8045632AC0 for ; Tue, 19 Jan 2010 10:27:52 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 51654-09 for ; Tue, 19 Jan 2010 14:27:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f220.google.com (mail-bw0-f220.google.com [209.85.218.220]) by mail.postgresql.org (Postfix) with ESMTP id CD0556327A5 for ; Tue, 19 Jan 2010 10:27:41 -0400 (AST) Received: by bwz20 with SMTP id 20so3110045bwz.34 for ; Tue, 19 Jan 2010 06:27:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=5AzGmV3K2T2SmEPrlX+1jJsFT/75nAKQGnicv4GibGs=; b=k2JR1N2zcb+9He9yiAhvFXF0tC7zMfPUHKMRbxhXBfPJbKL9IMnWYZS2QYrmA+SltW 6Jns/mJa/tXxRUGcBqHAGpEqAB4mV7XO0SvVX1BN3vaMKVEn51JOZ1vEiZk49Kmg6BPG y85OiL4EGBgz/Fu9g9v2QvldXCpMcrgCpipig= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=q0bTHdQ1ICaWkIWI5YLlOV8jC49n7SEehJzG8/5NQXLgoqZMhnevzBSmWAzlfM2iX0 /lWuQi8sXcQlowch+wEyyU5n/6oWUBJqw21gAjPRqk+qmeCpbEuSOfBz1g3kG4IsCBq2 bCOzojMtsDuIo4DB7ezWZM5myAzGAFl7ICtGk= MIME-Version: 1.0 Received: by 10.204.5.207 with SMTP id 15mr775202bkw.89.1263911259711; Tue, 19 Jan 2010 06:27:39 -0800 (PST) In-Reply-To: <4B54FDF3.4070601@gmx.net> References: <4B54FDF3.4070601@gmx.net> Date: Tue, 19 Jan 2010 15:27:39 +0100 Message-ID: <92869e661001190627i4d42e368nbb0e96bf5c54ca76@mail.gmail.com> Subject: Re: How to cascade information like the user roles ? From: =?UTF-8?Q?Filip_Rembia=C5=82kowski?= To: Andreas Cc: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=00151758864eaa7998047d8545dd X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.289 tagged_above=-10 required=5 tests=AWL=0.309, BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201001/35 X-Sequence-Number: 33571 --00151758864eaa7998047d8545dd Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2010/1/19 Andreas > Hi, > > I need something like the user-roles of PG to store options of my users. > I guess i need a table with roles, options and one that stores the > refernces from roles to options. > > roles (role_id, role_name) > option (option_id, option_name) > role_has_option (role_fk, option_fk) > > so far is easy. Now I can let role1 have option1 and option2 ... > > But I'd further like to let role2 inherit role1's options and also have > option3. > role_inherits_role (parent_role_fk, child_role_fk) > 1, 2 > > What SELECT would deliver all options for role2 inkluding the inherited > ones? > like > role_id, option_id > 2, 1 > 2, 2 > 2, 3 > select role_fk as role_id, option_fk as option_id from role_has_option wher= e role_fk =3D 2 union select inh.child_role_fk, opt.option_fk from role_has_option opt join role_inherits_role inh on inh.parent_role_fk =3D opt.role_fk where inh.child_role_fk =3D 2 ? > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > --=20 Filip Rembia=C5=82kowski JID,mailto:filip.rembialkowski@gmail.com http://filip.rembialkowski.net/ --00151758864eaa7998047d8545dd Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

2010/1/19 Andreas <= maps.on@gmx.net>
Hi,

I need something like the user-roles of PG to store options of my users. I guess i need a table with roles, options and one that stores the refernce= s from roles to options.

roles (role_id, role_name)
option (option_id, option_name)
role_has_option (role_fk, option_fk)

so far is easy. Now I can let role1 have option1 and option2 ...

But I'd further like to let role2 inherit role1's options and also = have option3.
role_inherits_role (parent_role_fk, child_role_fk)
1, 2

What SELECT would deliver all options for role2 inkluding the inherited one= s?
like
role_id, option_id
2, 1
2, 2
2, 3


select role_fk as role_id, option_fk as o= ption_id from role_has_option where role_fk =3D 2
union
select inh.ch= ild_role_fk, opt.option_fk from role_has_option opt join role_inherits_role= inh on inh.parent_role_fk =3D opt.role_fk where inh.child_role_fk =3D 2

?



--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
= http://www.postgresql.org/mailpref/pgsql-sql



--
Filip Rembia=C5= =82kowski
JID,mailto:fi= lip.rembialkowski@gmail.com
http://filip.rembialkowski.net/
--00151758864eaa7998047d8545dd--