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 AACEB9FB22F for ; Sat, 15 Jul 2006 06:24:22 -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 25506-08 for ; Sat, 15 Jul 2006 06:24:19 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.177]) by postgresql.org (Postfix) with ESMTP id 2EEAD9FB227 for ; Sat, 15 Jul 2006 06:24:18 -0300 (ADT) Received: by py-out-1112.google.com with SMTP id 57so773378pya for ; Sat, 15 Jul 2006 02:24:17 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=sniEnYmt9psSdV/dluMpIkS4QYuiHxs/xZ3uRAXznJ5l0sk5H31WAeckAoVluhIt2LPKVcgV7la5tWJo6qvdp0UTdIxK1DztmJxBpXY57Qp93aRrbYlZUmk/GM1Hny9HjKVsGL3Jj8KoE8Wl1Y79fYQpVLd6aGp0aU5+trSklKg= Received: by 10.35.37.13 with SMTP id p13mr717244pyj; Sat, 15 Jul 2006 02:24:17 -0700 (PDT) Received: by 10.35.76.4 with HTTP; Sat, 15 Jul 2006 02:24:17 -0700 (PDT) Message-ID: Date: Sat, 15 Jul 2006 11:24:17 +0200 From: "Stefan Arentz" To: pgsql-sql@postgresql.org Subject: Querying for name/value pairs in reverse MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/213 X-Sequence-Number: 25787 I'm no SQL expert by any means so I'm wondering if something like this is possible. I have two tables like this: create table Errors ( Id serial not null, CreateDate timestamp not null, primary key (Id) ); create table ErrorValues ( Id serial not null, ErrorId int not null, Name varchar(255) not null, Value text not null, primary key (Id), foreign key (ErrorId) references Errors (Id) ); Now, selecting specific ErrorValues with a bunch of names that are related to an Error is of course pretty simple. But I want to go the other way. I want to query for: 'give me all Errors that have the Code=1234 AND Address=1.2.3.4 AND Type=OSX Name/Value pairs' What is a good recipe to deal with this? Is something like this possible with standard sql? Is there a nice PG way to do this? Are there good books that cover real world stuff like this? So many questions from a SQL noob. S.