Skip site navigation (1) Skip section navigation (2)

ruby/postgres - getting assoc array of rows?

From: CSN <cool_screen_name90001(at)yahoo(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: ruby/postgres - getting assoc array of rows?
Date: 2005-11-20 04:14:40
Message-ID: 20051120041440.29069.qmail@web52902.mail.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
Looking at the docs here:
http://ruby.scripting.ca/postgres/reference.html

there doesn't appear to be an easy way to get an associative row of rows returns. Looking in Rails
PG code, I see this convolution:

        def select(sql, name = nil)
          res = execute(sql, name)
          results = res.result
          rows = []
          if results.length > 0
            fields = res.fields
            results.each do |row|
              hashed_row = {}
              row.each_index do |cel_index|
                column = row[cel_index]
                if res.type(cel_index) == BYTEA_COLUMN_TYPE_OID
                  column = unescape_bytea(column)
                end
                hashed_row[fields[cel_index]] = column
              end
              rows << hashed_row
            end
          end
          return rows
        end

Is there a much easier and simpler way?

csn


	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Responses

pgsql-interfaces by date

Next:From: Michael FuhrDate: 2005-11-20 05:32:47
Subject: Re: ruby/postgres - getting assoc array of rows?
Previous:From: Murray CummingDate: 2005-11-19 17:34:18
Subject: Detecting postgres servers

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group