[ACCEPTED]-How do you efficiently determine if a Postgres table has rows-postgresql
Accepted answer
select true from table limit 1;
0
select exists(select * from your_table_here) as has_row
0
Try this:
SELECT t.primary_key IS NOT NULL FROM table t LIMIT 1;
You will get TRUE if there are 1 records and NULL if there are none.
If all you care about is 1 row or no rows. Limit 5 your query to the first row - why count 4 all of the rows just to find out if there's 3 1 or more, or zero...
use the equivalent 2 of ROWNUM = 1 or TOP 1 or whatever postgres 1 gives you.
How a count on the primary key field where 3 it is NOT NULL, limiting the query at 1 2 response?
Since a primary key must exist, if 1 there is one, you have data, yes?
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.