X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 23603DBCA3 for ; Sun, 20 Nov 2005 01:52:33 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70496-06 for ; Sun, 20 Nov 2005 05:52:32 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 75EDCDBC29 for ; Sun, 20 Nov 2005 01:52:30 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id jAK5qRtE052890 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 19 Nov 2005 22:52:30 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id jAK5qRqU031569; Sat, 19 Nov 2005 22:52:27 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jAK5qR72031568; Sat, 19 Nov 2005 22:52:27 -0700 (MST) (envelope-from mfuhr) Date: Sat, 19 Nov 2005 22:52:27 -0700 From: Michael Fuhr To: CSN Cc: pgsql-interfaces@postgresql.org Subject: Re: ruby/postgres - getting assoc array of rows? Message-ID: <20051120055226.GA31492@winnie.fuhr.org> References: <20051120041440.29069.qmail@web52902.mail.yahoo.com> <20051120053247.GA31157@winnie.fuhr.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051120053247.GA31157@winnie.fuhr.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[AWL=0.000] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/53 X-Sequence-Number: 5849 On Sat, Nov 19, 2005 at 10:32:47PM -0700, Michael Fuhr wrote: > You could also convert the PGresult object into an array of PGrow > objects with a one-liner, although you wouldn't get automatic bytea > handling as in the function you posted: > > rows = res.collect Other possibilities are res.to_a, res.entries, res.result, and res.rows, which all do the same thing: return an array of PGrow objects. The collect, to_a, and entries methods are provided by the Enumerable mixin; the result and rows methods are aliases for entries, which is synonymous with to_a. Using any of these methods ultimately results in calling PGresult#each, which yields the PGrow objects. -- Michael Fuhr