Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 901BE9FB324 for ; Fri, 19 Jan 2007 21:45:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 63125-10 for ; Fri, 19 Jan 2007 21:45:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from wolff.to (wolff.to [66.93.197.194]) by postgresql.org (Postfix) with SMTP id CA55C9FB391 for ; Fri, 19 Jan 2007 21:45:27 -0400 (AST) Received: (qmail 32647 invoked by uid 500); 20 Jan 2007 01:45:24 -0000 Date: Fri, 19 Jan 2007 19:45:24 -0600 From: Bruno Wolff III To: mawrya Cc: pgsql-sql@postgresql.org Subject: Re: select based on multi-column primary keys Message-ID: <20070120014524.GC30390@wolff.to> Mail-Followup-To: Bruno Wolff III , mawrya , pgsql-sql@postgresql.org References: <45B16602.2080508@furthernorth.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <45B16602.2080508@furthernorth.net> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/87 X-Sequence-Number: 27239 On Fri, Jan 19, 2007 at 16:44:50 -0800, mawrya wrote: > I have set up a table with a multi-column primary key constraint: > > If I had a row in the table where systemid=123, enclosureid=ab, > pointid=56, I would have a Primary Key ("ID") of 123ab56 for that row. > > I now want to run a select based on the Primary Key, something like: > > SELECT * FROM iopoints WHERE ID = 123ab56 > > Is something like this even possible? Or am I forced to do: > > SELECT * FROM iopoints WHERE systemid=123 AND enclosureid=ab AND pointid=56 SELECT * FROM iopoints WHERE systemid=123 AND enclosureid='ab' AND pointid=56 While in theory you could concatenate the columns and test that against a particular value, you probably don't want to do that. (If you do, use a functional index.)