How to check a table content efficiently? With LIMIT and OFFSET?

From: Stefan Keller <sfkeller(at)gmail(dot)com>
To: pgsql-general List <pgsql-general(at)postgresql(dot)org>
Subject: How to check a table content efficiently? With LIMIT and OFFSET?
Date: 2011-05-28 19:13:12
Message-ID: BANLkTimBWAzy7NzimfVCUEBw_gg=4MoLng@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I’d like to monitor a table in a read-only Postgres database by
writing a PL/pgSQL function.
The database gets periodically overwritten by a mirroring loading process.
The success criteria is, that the table contains at least some records
(actually at least more than 100000).

The first idea which comes to one’s mind is probably a count(*):

SELECT CASE WHEN (count(*) > 10000) THEN 'yes' ELSE 'no' END
FROM planet_osm_point;

But my goal is to consume as few Postgres server resources as possible.
So my idea is to retrieve an arbitrary record, like this:

SELECT CASE WHEN (osm_id::text > '') THEN 'yes' ELSE 'no' END
FROM planet_osm_point LIMIT 1 OFFSET 1000000;

Is there anyone having an even better better idea?

Yours, Stefan

Responses

Browse pgsql-general by date

  From Date Subject
Next Message preetika tyagi 2011-05-28 19:24:11 Re: Shared Buffer Size
Previous Message Andrej Podzimek 2011-05-28 15:02:24 Regular disk activity of an idle DBMS