X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E43CC9FA3B4 for ; Sat, 15 Jul 2006 19:26:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 99221-07 for ; Sat, 15 Jul 2006 19:26:30 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.184]) by postgresql.org (Postfix) with ESMTP id 16E289F95E3 for ; Sat, 15 Jul 2006 19:26:29 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id p77so168466nfc for ; Sat, 15 Jul 2006 15:26:28 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=U8EwPHTXv4IxNfEybeUj0fBik88qRZci/T2VNSEFrsd9XNhKXZQMix2uAAFrMxuz9aPRWQr8cUNtT6WPp4DJhNwa02fdAnYumD6FUaWnW4/KDVKkTidvUk8EjWiAUBcJeCkSx3vLwZJ3NBmKsPSCRlHD2Lrvx5oVwd0hFQjix6A= Received: by 10.78.175.14 with SMTP id x14mr279981hue; Sat, 15 Jul 2006 15:26:28 -0700 (PDT) Received: by 10.78.29.15 with HTTP; Sat, 15 Jul 2006 15:26:28 -0700 (PDT) Message-ID: Date: Sat, 15 Jul 2006 17:26:28 -0500 From: "Aaron Bono" To: "Paul S" Subject: Re: Querying for name/value pairs in reverse Cc: pgsql-sql@postgresql.org, stefan.arentz@gmail.com In-Reply-To: <866624ef0607150500h537f496byc489affa019f996d@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_42818_20095577.1153002388259" References: <866624ef0607150500h537f496byc489affa019f996d@mail.gmail.com> X-Google-Sender-Auth: 1537133519a7d9bd X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/219 X-Sequence-Number: 25793 ------=_Part_42818_20095577.1153002388259 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/15/06, Paul S wrote: > > This is definitely doable. > > one "Set" way that I could think of doing this would be to first compile a > temp table with all of the Value/Pairs that your looking to search for and > then just JOIN the ID's (in this case it would be the Value and Pair) to the > ErrorValues table. This should give you all of the ErrorID's in the > ErrorValues table which would then allow you to JOIN up against the Errors > table to get information like CreateDate. > This works - the subselect I sent earlier kind of does this (the subselect can act as a temp table in memory so you don't have to create a physical one). Another way, would be to use XML instead of Value/Pair to turn it into a > Node and Value type of thing. You could then use XQuery to search inside of > the XML attribute for what you were looking for. SET theory would be a > better alternative but this is just a different idea. > I wonder if the use of XML in a database is a very good idea. (am I treading on religious territory here?) I can think of some examples where XML can be useful but the problem I see with it is that your data structure is embedded in a single field and your database schema does not describe your data structure very well anymore. I always like to use the database schema as a way to document the data structure so if you have the DB diagrams, you can understand everything there. One Naming convention tip, I like to name my PrimaryKey's something more > descriptive than just ID. You'll notice that your ErrorValues table had to > include the foreign key called ErrorID that actually relates to attribute ID > in the Errors table. When your looking at miles and miles of code or > reviewing JOIN syntax " a.ID = b.ErrorID" sometimes it's easier to > validate if it looks like this. "a.ErroID = b.ErrorID". Just my 2 > cents... > I wholeheartedly agree. If you don't adopt a good naming convention like this, you will come to regret it as your application grows in size and complexity. ================================================================== Aaron Bono Aranya Software Technologies, Inc. http://www.aranya.com ================================================================== ------=_Part_42818_20095577.1153002388259 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/15/06, Paul S <plabrh1@gmail.com> wrote:
This is definitely doable. 
 
one "Set" way that I could think of doing this would be to first compile a temp table with all of the Value/Pairs that your looking to search for and then just JOIN the ID's (in this case it would be the Value and Pair) to the ErrorValues table.  This should give you all of the ErrorID's in the ErrorValues table which would then allow you to JOIN up against the Errors table to get information like CreateDate. 

This works - the subselect I sent earlier kind of does this (the subselect can act as a temp table in memory so you don't have to create a physical one).

Another way, would be to use XML instead of Value/Pair to turn it into a Node and Value type of thing.  You could then use XQuery to search inside of the XML attribute for what you were looking for.  SET theory would be a better alternative but this is just a different idea. 

I wonder if the use of XML in a database is a very good idea.  (am I treading on religious territory here?)  I can think of some examples where XML can be useful but the problem I see with it is that your data structure is embedded in a single field and your database schema does not describe your data structure very well anymore.  I always like to use the database schema as a way to document the data structure so if you have the DB diagrams, you can understand everything there.

One Naming convention tip, I like to name my PrimaryKey's something more descriptive than just ID.  You'll notice that your ErrorValues table had to include the foreign key called ErrorID that actually relates to attribute ID in the Errors table.  When your looking at miles and miles of code or reviewing JOIN syntax " a.ID = b.ErrorID" sometimes it's easier to validate if it looks like this. "a.ErroID = b.ErrorID ".  Just my 2 cents...

I wholeheartedly agree.  If you don't adopt a good naming convention like this, you will come to regret it as your application grows in size and complexity.

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
================================================================== ------=_Part_42818_20095577.1153002388259--