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

217
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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