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

216
Visualizações
undefined method `empty?' for #<PG::Result:0x007fcc82900a78>

We migrated our database from sqlite3 to postgreSQL. Now, at the following line, we get an error:

  def self.get_table_id(id)
    sql = "SELECT id FROM configtables WHERE parent = 'check' AND parentid = " + id.to_s
    results = connection.execute(sql)
    return nil if results.empty? # here's where the error happens
    return results[0][0]
  end

I have less knowledge of Ruby and ActiveRecords and with postgreSQL as well. Is the value in results a postgres-object, or whats #<PG::Result:0x007fcc82900a78> and what was it with the sqlite3 database?

This function is one of a few with raw sql-strings.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

empty? is not defined for PG::Result:

PG::Result.instance_methods.include?(:empty?)
#=> false

To use empty? you should convert the result to an instance of Array:

results.to_a.empty?
over 4 years ago · Santiago Trujillo Relatório

0

Seems like you should "fetch" actual results from PG::Result object.
One way of doing this could be calling to_a

Try the following:

sql = "SELECT id FROM configtables WHERE parent = 'check' AND parentid = " + id.to_s
results = ActiveRecord::Base.connection.execute(sql).to_a
...
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