# Testing Result of raw sql query

**URL:** <https://www.ruby-forum.com/t/testing-result-of-raw-sql-query/103308>\
**Category:** Rails\
**Created:** [May 4, 2007, 1:44am UTC](https://www.ruby-forum.com/t/testing-result-of-raw-sql-query/103308 "2007-05-04T01:44:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cephas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e0b2c6/32.png) [@cephas](https://www.ruby-forum.com/u/cephas)\
**Post date:** [May 4, 2007, 1:44am UTC](https://www.ruby-forum.com/t/testing-result-of-raw-sql-query/103308/1 "2007-05-04T01:44:22Z")

</div>

I need to be able to catch when my postgresql database returns no rows  
in a raw sql query.  
In this case it would be an error indicating that the long and lat are  
outside of the  
shape file.

s = Boundary.find\_by\_sql(“SELECT name, country, stateabb FROM  
boundaries WHERE distance( the\_geom,‘POINT(#{@lon} #{@lat})’) = 0”)

testing with s.nil! does not seem to solve the problem

Any ideas?

Here are two queries one without a record and one with

# SELECT name, country, stateabb FROM boundaries WHERE

distance( the\_geom,‘POINT(-89.0 0.0)’) = 0;  
name | country | stateabb  
------±--------±---------  
(0 rows)

# SELECT name, country, stateabb FROM boundaries WHERE

distance( the\_geom,‘POINT(-89.0 43.0)’) = 0;  
name | country | stateabb  
-----------±--------±---------  
Wisconsin | USA | US-WI  
(1 row)

---

<div class="post-metadata">

**Author:** ![cephas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e0b2c6/32.png) [@cephas](https://www.ruby-forum.com/u/cephas)\
**Post date:** [May 4, 2007, 1:53am UTC](https://www.ruby-forum.com/t/testing-result-of-raw-sql-query/103308/2 "2007-05-04T01:53:22Z")

</div>

On May 3, 2007, at 7:43 PM, Pete wrote:

> testing with s.nil! does not seem to solve the problem

s.empty? ?

-faisal

---

<div class="post-metadata">

**Author:** ![cephas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e0b2c6/32.png) [@cephas](https://www.ruby-forum.com/u/cephas)\
**Post date:** [May 4, 2007, 4:43am UTC](https://www.ruby-forum.com/t/testing-result-of-raw-sql-query/103308/3 "2007-05-04T04:43:33Z")

</div>

I would recommend to trace log/development.log to check the actual SQL  
statement being executed by Rails.
