Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!