pg.ddx.io pgsql-performance@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Re: Find one record 2+ messages / 2 participants [nested] [flat]
* Find one record @ 2003-09-18 18:01 Joseph Bove <jbove@vetstar.com> 2003-09-18 17:53 ` Re: Find one record Josh Berkus <josh@agliodbs.com> 0 siblings, 1 reply; 2+ messages in thread From: Joseph Bove @ 2003-09-18 18:01 UTC (permalink / raw) To: pgsql-performance Dear list, 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. 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. Does anyone have a better way to do this? Regards ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Find one record 2003-09-18 18:01 Find one record Joseph Bove <jbove@vetstar.com> @ 2003-09-18 17:53 ` Josh Berkus <josh@agliodbs.com> 0 siblings, 0 replies; 2+ messages in thread From: Josh Berkus @ 2003-09-18 17:53 UTC (permalink / raw) To: Joseph Bove <jbove@vetstar.com>; pgsql-performance 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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-09-18 18:01 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2003-09-18 18:01 Find one record Joseph Bove <jbove@vetstar.com> 2003-09-18 17:53 ` Josh Berkus <josh@agliodbs.com>
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