to get a column as array

Issue #12 resolved
Michael Granger repo owner created an issue

Via Sugano Yoshihisa in [[http://rubyforge.org/tracker/index.php?func=detail&aid=23503&group_id=3214&atid=12398|Rubyforge Patch 12398]] (formatting mine):

Hi. I expect to get only primary key from much data. But entiries method was too late and I don't need field name.

And so I added function {{{getfieldvalues()}}} in {{{pg.c}}}. {{{getfiledvalues()}}} will return a column as array.

{{{ 87136 rows data get: filedvalues: array in 87136 (0.045936) entries : array in 87136 (0.273321) }}}

example: {{{ #!ruby result = conn.exec(sql) array = result.getrfiledvalues(0) }}}

If you want to get 2nd field: {{{ #!ruby array = result.getrfiledvalues(1) }}}

Comments (3)

  1. Michael Granger reporter
    • changed status to open

    Since PostgreSQL refers to the values in result tuples as 'columns' and the values by name as 'fields', I'm going to modify this patch a bit to add two new methods:

    • PGresult#column_values( n ) - Return the nth value from each tuple in the result.
    • PGresult#field_values( field ) - Return the value associated with field for each tuple in the result.

    I'll also set the encoding of the returned values.

  2. Michael Granger reporter

    Added column-selection methods to PGresult (#field_values and #column_values). Closes #12. Thanks to Sugano Yoshihisa for the patch on which these methods were based.

    42919e2a4ef8

  3. Log in to comment