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 21867D688E for ; Sun, 20 Nov 2005 11:56:15 -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 94023-01 for ; Sun, 20 Nov 2005 15:56:19 +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 5F88FD6857 for ; Sun, 20 Nov 2005 11:56:12 -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 jAKFuEc1053651 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 20 Nov 2005 08:56:16 -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 jAKFuEKX038939; Sun, 20 Nov 2005 08:56:14 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jAKFuEWq038938; Sun, 20 Nov 2005 08:56:14 -0700 (MST) (envelope-from mfuhr) Date: Sun, 20 Nov 2005 08:56:14 -0700 From: Michael Fuhr To: CSN Cc: pgsql-interfaces@postgresql.org Subject: Re: ruby/postgres - getting assoc array of rows? Message-ID: <20051120155613.GB38669@winnie.fuhr.org> References: <20051120053247.GA31157@winnie.fuhr.org> <20051120103145.96545.qmail@web52901.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051120103145.96545.qmail@web52901.mail.yahoo.com> 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/55 X-Sequence-Number: 5851 On Sun, Nov 20, 2005 at 02:31:45AM -0800, CSN wrote: > I tried: > puts "by name: #{row['id']} #{row['name']}" > > but it exits with: > pg.rb:16:in `[]': can't convert String into Integer (TypeError) What versions of Ruby and ruby-postgres are you using? Did you use exactly the code I posted or did you do something different? The only way to get a PGrow object (other than building it yourself) is from PGresult#each or some method that calls it, so this won't work: conn = PGconn.new('dbname=test') result = conn.exec('SELECT 1 AS x') row = result[0] # returns an Array puts row['x'] # raises TypeError but this does work: row = result.to_a[0] # returns a PGrow puts row['x'] I'm not sure if the PGrow behavior is version-specific. I don't see it mentioned in the ruby-postgres ChangeLog, so I'd have to dig a little more to find out. -- Michael Fuhr