X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7C1CCD1B4F6 for ; Thu, 18 Sep 2003 17:54:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 14006-03 for ; Thu, 18 Sep 2003 14:54:00 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 54378D1B4F0 for ; Thu, 18 Sep 2003 14:53:59 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3653966; Thu, 18 Sep 2003 10:54:29 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Joseph Bove , pgsql-performance@postgresql.org Subject: Re: Find one record Date: Thu, 18 Sep 2003 10:53:57 -0700 User-Agent: KMail/1.4.3 References: <24864010.1063897195181.JavaMail.root@statler.psp.pas.earthlink.net> <5.1.0.14.2.20030918135557.03ab89d8@mail.vetstar.com> In-Reply-To: <5.1.0.14.2.20030918135557.03ab89d8@mail.vetstar.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200309181053.57709.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/274 X-Sequence-Number: 3640 Joseph, > I hope this to be a simple question. I have need to simply read the first > row in a given table. Right now, I have some legacy code that selects all > rows in a table just to see if the first row has a certain value. Your problem is conceptual: in SQL, there is no "first" row. If you want to just pick a single row at random, do SELECT * FROM table LIMIT 1; Or if you have a primary key id, you could for example return the row with the lowest id: SELECT * FROM table ORDER BY id LIMIT 1; > The code is seeking to see if an update has been run or not. A hypothetical > scenario would be: has an update been run to populate data into a new > column in a table. Neither the data nor any of the rows are consistently > known. So the test selects all rows, tests the first row and then ends if > the column has a value. I'd write an ON UPDATE trigger, personally, to fire and write data somewhere else whenever the table is updated. Much more reliable .... -- Josh Berkus Aglio Database Solutions San Francisco