Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

0

SELECT COUNT(*) FROM table_name limit 1;

Try this code .

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda