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 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2005-11-20 05:32:47 | Re: ruby/postgres - getting assoc array of rows? |
Previous Message | Murray Cumming | 2005-11-19 17:34:18 | Detecting postgres servers |