# Problems with Rails and Postgres

**URL:** <https://www.ruby-forum.com/t/problems-with-rails-and-postgres/165722>\
**Category:** Rails\
**Created:** [April 16, 2009, 7:10pm UTC](https://www.ruby-forum.com/t/problems-with-rails-and-postgres/165722 "2009-04-16T19:10:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [April 16, 2009, 7:10pm UTC](https://www.ruby-forum.com/t/problems-with-rails-and-postgres/165722/1 "2009-04-16T19:10:16Z")

</div>

Hi all,

i have a method that I use in the ‘after\_save’ that is implemented as  
follows:

def verify  
a =11674  
x = self.aui\_codigo

```
  reinc =AutoInfracao.find_by_sql("select age((select aui_data_lav

```

from tb\_aui\_auto\_infracao where aui\_codigo=#{a}),  
(select max(aui\_data\_lav)from tb\_aui\_auto\_infracao where aui\_codigo  
in(select a.aui\_codigo from tb\_aur\_auto\_inf\_regular a,tb\_iau\_itens\_auto  
i where a.for\_cod =(select for\_cod from tb\_aur\_auto\_inf\_regular where  
aui\_codigo=#{a}) and a.lir\_codigo=(select lir\_codigo from  
tb\_aur\_auto\_inf\_regular where aui\_codigo = #{a}) and i.inf\_codigo =  
(select inf\_codigo from tb\_iau\_itens\_auto where aui\_codigo = #{a}) and  
a.aui\_codigo\<\>#{a} and a.aui\_codigo = i.aui\_codigo)))")

```
print reinc[0].age

```

end

the ‘a’ and the ‘x’ variables have the same value(11674) and the same  
type(FixNum).Curiously,I can run my query using the ‘a’ variable,but I  
cannot run it using the ‘x’ variable.What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [April 18, 2009, 11:19am UTC](https://www.ruby-forum.com/t/problems-with-rails-and-postgres/165722/2 "2009-04-18T11:19:55Z")

</div>

Rafael R. wrote:

> Hi all,

Have you looked at the SQL generated in the log directory?

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [April 20, 2009, 3:51pm UTC](https://www.ruby-forum.com/t/problems-with-rails-and-postgres/165722/3 "2009-04-20T15:51:38Z")

</div>

Wisccal W. wrote:

> Rafael R. wrote:
> 
> > Hi all,
> 
> Have you looked at the SQL generated in the log directory?

Yep…

If I grab the sql in the output directly in the pgAdmin and execute it,I  
get the correct result.

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [April 20, 2009, 7:25pm UTC](https://www.ruby-forum.com/t/problems-with-rails-and-postgres/165722/4 "2009-04-20T19:25:12Z")

</div>

What kind of error do you get, exactly?

On Apr 16, 1:10 pm, Rafael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
