pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Joseph Bove <jbove@vetstar.com>
To: pgsql-performance@postgresql.org
Subject: Re: Find one record
Date: Thu, 18 Sep 2003 10:53:57 -0700
Message-ID: <200309181053.57709.josh@agliodbs.com> (raw)
In-Reply-To: <5.1.0.14.2.20030918135557.03ab89d8@mail.vetstar.com>
References: <24864010.1063897195181.JavaMail.root@statler.psp.pas.earthlink.net>
	<5.1.0.14.2.20030918135557.03ab89d8@mail.vetstar.com>

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



view thread (2+ messages)  latest in thread

Message-ID: <200309181053.57709.josh@agliodbs.com>
Permalink:  ../200309181053.57709.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200309181053.57709.josh@agliodbs.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: josh@agliodbs.com, jbove@vetstar.com
  Subject: Re: Find one record
  In-Reply-To: <200309181053.57709.josh@agliodbs.com>
  References: <24864010.1063897195181.JavaMail.root@statler.psp.pas.earthlink.net> <5.1.0.14.2.20030918135557.03ab89d8@mail.vetstar.com> <200309181053.57709.josh@agliodbs.com>

* 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