From: CSN <cool_screen_name90001@yahoo.com>
To: pgsql-interfaces@postgresql.org
Subject: ruby/postgres - getting assoc array of rows?
Date: Sat, 19 Nov 2005 20:14:40 -0800 (PST)
Message-ID: <20051120041440.29069.qmail@web52902.mail.yahoo.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: cool_screen_name90001@yahoo.com
Subject: Re: ruby/postgres - getting assoc array of rows?
In-Reply-To: <20051120041440.29069.qmail@web52902.mail.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox