pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: mawrya <mawrya@furthernorth.net>
To: pgsql-sql@postgresql.org
Subject: select based on multi-column primary keys
Date: Fri, 19 Jan 2007 16:44:50 -0800
Message-ID: <45B16602.2080508@furthernorth.net> (raw)

I have set up a table with a multi-column primary key constraint:

CREATE TABLE iopoints
(
  enclosureid numeric(3) NOT NULL,
  pointid char(4) NOT NULL,
  equipmentgroup varchar(64) NOT NULL,
  deviceid varchar(8),
  devicetype varchar(24),
  operationdesc varchar(64) NOT NULL,
  entrytime timestamp NOT NULL DEFAULT ('now'::text)::timestamp(6) with 
time zone,
  systemid numeric(3) NOT NULL,
  CONSTRAINT "ID" PRIMARY KEY (systemid, enclosureid, pointid)
)
WITHOUT OIDS;

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

I have searched high and low but can not find a syntax example of how to 
select based on a multi-column primary key, any tips?

Thanks,

mawrya



view thread (7+ messages)  latest in thread

Message-ID: <45B16602.2080508@furthernorth.net>
Permalink:  ../45B16602.2080508@furthernorth.net/
Also on:    postgresql.org/message-id/45B16602.2080508@furthernorth.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mawrya@furthernorth.net
  Subject: Re: select based on multi-column primary keys
  In-Reply-To: <45B16602.2080508@furthernorth.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox