B
B
beduin012021-07-23 19:31:24
PostgreSQL
beduin01, 2021-07-23 19:31:24

Is it possible to use COUNT(*) along with Limit?

I need to check if there are more files in the database than 1000.
COUNT(*) is not suitable for me. takes too long, is there any quick way to just know if there are enough files to process or not? Thus without scanning all table.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2021-07-23
@beduin01

try like this

select count(*) from 
(select * from some_table limit 1000) a

A
Armenian Radio, 2021-07-23
@gbg

Get an index in the table and count, for example, count(id).
Another option is to have triggers for insertion and deletion so that they change the corresponding counter. But here it is necessary to carefully organize transactions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question