[] (PGresult)

    /*
     * call-seq:
     *    res[ n ] -> Hash
     *
     * Returns tuple _n_ as a hash.
     */
    static VALUE
    pgresult_aref(VALUE self, VALUE index)
    {
            PGresult *result = get_pgresult(self);
            int tuple_num = NUM2INT(index);
            int field_num;
            VALUE fname,val;
            VALUE tuple;

            if(tuple_num >= PQntuples(result))
                    rb_raise(rb_eIndexError, "Index %d is out of range", tuple_num);
            tuple = rb_hash_new();
            for(field_num = 0; field_num < PQnfields(result); field_num++) {
                    fname = rb_tainted_str_new2(PQfname(result,field_num));
                    if(PQgetisnull(result, tuple_num, field_num)) {
                            rb_hash_aset(tuple, fname, Qnil);
                    }
                    else {
                            val = rb_tainted_str_new(PQgetvalue(result, tuple_num, field_num),
                                    PQgetlength(result, tuple_num, field_num));
                            rb_hash_aset(tuple, fname, val);
                    }
            }
            return tuple;
    }