Problems with Rails and Postgres

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?

Rafael R. wrote:

Hi all,

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

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.

What kind of error do you get, exactly?

On Apr 16, 1:10 pm, Rafael R. [email protected]