Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
What's the fastest way to see if a table has no rows in postgreSQL?

I have a bunch of tables that I'm iterating through, and some of them have no rows (i.e. just a table of headers with no data). ex: SELECT my_column FROM my_schema.my_table LIMIT 1 returns an empty result set.

What is the absolute fastest way to check that a table is one of these tables with no rows?

I've considered: SELECT my_column FROM my_schema.my_table LIMIT 1 or SELECT * FROM my_schema.my_table LIMIT 1 followed by an if result is None(I'm working in Python). Is there any faster way to check?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

This is not faster than your solution but returns a boolean regadless:

select exists (select 1 from mytable)
over 4 years ago · Santiago Trujillo Denunciar

0

select exists (select * from myTab);

or

select 1 where exists (select * from myTab)

or even

SELECT reltuples FROM pg_class WHERE oid = 'schema_name.table_name'::regclass;

The 3rd example uses the estimator to estimate rows, which may not be 100% accurate, but may be a tad bit faster.

over 4 years ago · Santiago Trujillo Denunciar

0

SELECT COUNT(*) FROM table_name limit 1;

Try this code .

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda