Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YYCdV-0002Ba-4W for pgsql-sql@arkaria.postgresql.org; Wed, 18 Mar 2015 11:59:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YYCdU-00036f-IF for pgsql-sql@arkaria.postgresql.org; Wed, 18 Mar 2015 11:59:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YYCdT-00034q-8r for pgsql-sql@postgresql.org; Wed, 18 Mar 2015 11:59:43 +0000 Received: from post.visena.com ([46.226.10.50]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YYCdP-0008Nb-2x for pgsql-sql@postgresql.org; Wed, 18 Mar 2015 11:59:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=visena.com; s=20141101.wh; h=Content-Type:MIME-Version:Subject:In-Reply-To:Message-ID:To:From:Date; bh=uGr69k8Qr3FMU3NdUDEejinKyGYD/C349GMLn15XFmk=; b=tTcHunYWXor+1JuhoNNGRV8ZZ48F6qMTDW7NUrYtKEo51iPkIBy96aeYCuDuXaNz3oTxIKjyVXewYzC+FdmJUvCtpKEdJF/PCr7ShrwqzxcQIrVstfO4EVRarNXnBREgjQyrUuh4NzhgwFIKKwLrhyjvRZacUDAxHgA+pf0AZ/U=; Received: from [10.0.1.10] (helo=tc7-visena.wh.internal.visena.com) by post.visena.com with esmtp (Exim 4.82) (envelope-from ) id 1YYCdL-0004mo-6K for pgsql-sql@postgresql.org; Wed, 18 Mar 2015 12:59:37 +0100 Received: from localhost ([127.0.0.1] helo=tc7-visena.wh.internal.visena.com) by tc7-visena.wh.internal.visena.com with esmtp (Exim 4.82) (envelope-from ) id 1YYCdL-0000DU-T4 for pgsql-sql@postgresql.org; Wed, 18 Mar 2015 12:59:35 +0100 Date: Wed, 18 Mar 2015 12:59:35 +0100 (CET) From: Andreas Joseph Krogh To: pgsql-sql@postgresql.org Message-ID: In-Reply-To: <1426676819968.86115@metametrics.co.uk> Subject: Re: Effective query for listing flags in use by messages in a folder MIME-Version: 1.0 X-Mailer: Visena Mail 1.9.0-SNAPSHOT X-Spam-Score: -1.0 X-Spam-Report: SpamAssasin (score=-1.0, required 5.0 ALL_TRUSTED=-1, HTML_MESSAGE=0.001) X-Pg-Spam-Score: -2.0 (--) Content-Type: multipart/related; boundary="----=_Part_134_1770453976.1426679975778" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org ------=_Part_133_1068846851.1426679975778 Content-Type: multipart/related; boundary="----=_Part_134_1770453976.1426679975778" ------=_Part_134_1770453976.1426679975778 Content-Type: multipart/alternative; boundary="----=_Part_135_439350017.1426679975796" ------=_Part_135_439350017.1426679975796 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 onsdag 18. mars 2015 kl. 12:07:00, skrev Hector Vass < hector.vass@metametrics.co.uk >: Andr= eas=20 =C2=A0... your code and one of my examples ...=C2=A0 I have modified my opt= ion 2 to give=20 an=C2=A0example with data=C2=A0that gives=C2=A0you I believe=C2=A0exactly t= he same output (one row=20 for each flag set for folder_id=3D3 with the text representation of the=20 flag)=C2=A0...=C2=A0when you satisfy yourself this produces the same result= s=C2=A0you might=20 then want to go back and re-read my original post which rather than feeding= =20 =C2=A0you verbatim how to produce exactly the same results gave the the pro= 's and=20 con's of 3x different approaches...=C2=A0I chose to illustrate my option 2 = because=20 it is easy to understand and is a reasonable production solution, option 1 = was=20 really just to get you thinking differently about how to do this and option= 3 I=20 concede was more advanced and probably=C2=A0but requires skills other than = plain SQL=20 to implement. =C2=A0 It's not that I didn't read you post, I just don't see how it solves= the=20 problem of listing a distinct set of flags being set on messages in a folde= r.=20 AFAICS your examples list messages with any or a specific set of flags set,= =20 which is not what I'm after. =C2=A0 I see now that I didn't specify the "ms= g"-column=20 so maybe it wasn't clear that the there's only one tuple in "message" for e= ach=20 message and a message may have several flags set. =C2=A0 This is a more rea= listic=20 table, with "msg" as varchar holding the actual text of the message: =C2=A0= create=20 table message( folder_id integer not NULL, msg varchar NOT NULL, is_seen=20 boolean NOT NULL default false, is_replied boolean not null default false,= =20 is_forwardedboolean not null default false, is_deleted boolean not null def= ault=20 false, is_draft boolean not null default false, is_flagged boolean not null= =20 default false); =C2=A0 -- Andreas Joseph Krogh CTO / Partner - Visena AS Mo= bile: +47=20 909 56 963 andreas@visena.com www.visena.com=20 =C2=A0 ------=_Part_135_439350017.1426679975796 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 onsdag 18. mars 2015 kl. 12:07:00, skrev Hector Vass <hector.vass@metametrics.co.uk>:

Andreas =C2=A0... your co= de and one of my examples ...=C2=A0 I have modified my option 2 to give an= =C2=A0example with data=C2=A0that gives=C2=A0you I believe=C2=A0exactly the= same output (one row for each flag set for folder_id=3D3 with the text rep= resentation of the flag)=C2=A0...=C2=A0when you satisfy yourself this produ= ces the same results=C2=A0you might then want to go back and re-read my ori= ginal post which rather than feeding =C2=A0you verbatim how to produce exac= tly the same results gave the the pro's and con's of 3x different approache= s...=C2=A0I chose to illustrate my option 2 because it is easy to understan= d and is a reasonable production solution, option 1 was really just to get = you thinking differently about how to do this and option 3 I concede was mo= re advanced and probably=C2=A0but requires skills other than plain SQL to i= mplement.

=C2=A0
It's not that I didn't read you post, I just don't see how it solves t= he problem of listing a distinct set of flags being set on messages in a fo= lder. AFAICS your examples list messages with any or a specific set of flag= s set, which is not what I'm after.
=C2=A0
I see now that I didn't specify the "msg"-column so maybe it= wasn't clear that the there's only one tuple in "message" for ea= ch message and a message may have several flags set.
=C2=A0
This is a more realistic table, with "msg" as varchar holdin= g the actual text of the message:
=C2=A0
create table message(
    folder_id =
integer no=
t NULL,
    msg varchar NOT NULL,
    is_seen boolean NOT =
NULL default false,
    is_replied=
 boolean n=
ot null default false,
    is_forward=
ed boolean=
 not null default false,
    is_deleted=
 boolean n=
ot null default false,
    is_draft <=
/span>boolean not=
 null default false,
    is_flagged=
 boolean n=
ot null default false
);
=C2=A0
=C2=A0
------=_Part_135_439350017.1426679975796-- ------=_Part_134_1770453976.1426679975778 Content-Type: image/png Content-Transfer-Encoding: base64 Content-Disposition: inline Content-ID: iVBORw0KGgoAAAANSUhEUgAAAIUAAAAYCAYAAADUIj6hAAAABHNCSVQICAgIfAhkiAAABzBJREFU aEPtmNFxHDcMhmVP3i1VECpvnjzkVIHWFfhcgVcVRKrAUgWRK/C6Al8H3lTgy0PGbzFdQc4VJP/H ADs43q6kROeJNbOYgQACIAgCWJKng4MZ5gxUGXh0U0b+SIuF9G+EWXj2Q15vbrE/NPtk9uub7Gfd t5mBx1NhqSEo8HshjbEUtlO2yIM9tsx5dZP9rPt2MzDZFAqZE4LGcFjdsg3saQaHt7fY70X949On aS+OZidDBkavD33157L4xaw2os+Mp/DAC10l2XhOCeStj0W5ajrJL8WfCi80Xgf9vVlrhg9yRONe /f7xI2vNsIcM7JwU9o6oGyJrLT8JOA1aX9sKP4wl94bAniukEbo/n7YPmuTETzIab4Y9ZWCrKexd 8M58lxPCvvD6aihfvexbEQoPYO8NQRO0JnddGO6FJYaVsBde7cXj7KRk4LsqDxQzCYeGsJNgaXZe +JXkyGgWINq3Gp+bHNILz+wEYs5qH1eJrouNrpDXtk4O6x1IvtD40GWyJYYdkF0jIbYZlN16xygI gl9smbMDsmFdfAKb23xGB8H/mv3tOJfArs1kukk79DEPdQ5u0g1vCvvqKXIW8mZYW+F3Tg4r8HvZ kQCCLydK8EFMQCe5N8RgL9mRG0SqQFuNvdE6beSs0qPDBuCdg0+gvClso8SbTO4ki7mQzQqBrc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