{"?column?"=>"t"} behavior

Issue #132 invalid
Stanislav Pankevich
created an issue


If I write

select exists (select true from #{table} limit 1);

The result, pg gem gives to me, is {"?column?"=>"t"} or {"?column?"=>"f"}

Can I expect the form of such response format to be stable across different versions of pg gem, earlier and future as well?

Or maybe there is a better way of parsing the result of such query, thus the generality of result parsed is ensured?

My use-case is here: https://github.com/stanislaw/truncate-vs-count/blob/master/truncate-vs-count-on-postgres.rb#L128


Comments (4)

  1. Lars Kanis

    You should give the column a name - this should be more stable as "?column?": select true as foo from #{table} limit 1; => {"foo"=>"t"}

    Since you are using ActiveRecord anyway, you may also better use pure AR methods:

      ActiveRecord::Base.connection.exec_query("select true as foo from #{table} limit 1").first
  2. Stanislav Pankevich reporter

    I am very sorry about not reacting in a proper time.

    Bitbucket didn't send me any notification, I've just looked here wondering if there any answers.

    Thanks for the answer! I am not mainly a PG user, so It is very good to know such simple, but very useful thing.

  3. Log in to comment