Queue in SQL - Mailing list pgsql-sql

From Gyorgy Molnar
Subject Queue in SQL
Date
Msg-id 001601c1774d$66bb1b90$3201a8c0@Athlon
Whole thread Raw
Responses Re: Queue in SQL  (Markus Bertheau <twanger@bluetwanger.de>)
Re: Queue in SQL  ("Andrew G. Hammond" <drew@xyzzy.dhs.org>)
Re: Queue in SQL  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
List pgsql-sql
Hi!

Question:
I need to store some incoming data and retrieve them one by one (LIFO).
Different processes will manage the storage and the retrieval.
How can I retrieve only the first row from a table?
==================

Explanation
I intend to use libpq and C. as far as I know to retrieve the result from a
query I need to do the following:

BEGIN A TRANSACTION
DECLARE CURSOR cursor FOR SELECT
FETCH one row from cursor
Process
CLOSE cursor
DELETE row
COMMIT

Let say I have 100,000 records in my table, I have to pick up only the first
row. I do not have any special criteria to execute a query, and I only need
the oldest added row (let say the first row if the table is indexed).
How can I narrow the search criteria, not to receive all of the 100,000
record in the result?
Unfortunately, I do not know the internal working of the SELECT. I think it
should create a temporary object to store the result. This object size may
depend on the number of the rows in the result and the size of the stored
data per row. I can fetch the rows one by one using this temporary object.

Kind Regards,
Gyorgy Molnar



pgsql-sql by date:

Previous
From: "Saira Somani"
Date:
Subject: Re: How can I return more than one row of data from pl/pgsql
Next
From: "Johnny Jørgensen"
Date:
Subject: PL/pgSQL loops?