Received: from femail12.sdc1.sfba.home.com (femail12.sdc1.sfba.home.com [24.0.95.108]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fARE9om94855 for ; Tue, 27 Nov 2001 09:09:50 -0500 (EST) (envelope-from gyorgy.molnar@home.com) Received: from Athlon ([24.102.196.32]) by femail12.sdc1.sfba.home.com (InterMail vM.4.01.03.20 201-229-121-120-20010223) with SMTP id <20011127140953.SGBL23187.femail12.sdc1.sfba.home.com@Athlon> for ; Tue, 27 Nov 2001 06:09:53 -0800 Message-ID: <001601c1774d$66bb1b90$3201a8c0@Athlon> From: "Gyorgy Molnar" To: Subject: Queue in SQL Date: Tue, 27 Nov 2001 09:11:18 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Archive-Number: 200111/379 X-Sequence-Number: 5761 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