Class PGresult
In: ext/postgres.c
Parent: Object

The class to represent the query result tuples (rows). An instance of this class is created as the result of every query. You may need to invoke the clear method of the instance when finished with the result for better memory performance.

Methods

[]   clear   close   cmd_tuples   cmdstatus   cmdtuples   each   fieldname   fieldnum   fields   ftype   getisnull   getlength   getvalue   getvalue_byname   nfields   ntuples   num_fields   num_tuples   oid   size   status   type  

Included Modules

Enumerable

Constants

EMPTY_QUERY = INT2FIX(PGRES_EMPTY_QUERY)
COMMAND_OK = INT2FIX(PGRES_COMMAND_OK)
TUPLES_OK = INT2FIX(PGRES_TUPLES_OK)
COPY_OUT = INT2FIX(PGRES_COPY_OUT)
COPY_IN = INT2FIX(PGRES_COPY_IN)
BAD_RESPONSE = INT2FIX(PGRES_BAD_RESPONSE)
NONFATAL_ERROR = INT2FIX(PGRES_NONFATAL_ERROR)
FATAL_ERROR = INT2FIX(PGRES_FATAL_ERROR)

External Aliases

entries -> result
entries -> rows

Public Instance methods

Returns the tuple (row) corresponding to n. Returns nil if n >= res.num_tuples.

Equivalent to res.result[n].

Clears the PGresult object as the result of the query.

close()

Alias for clear

Returns the number of tuples (rows) affected by the SQL command.

If the SQL command that generated the PGresult was not one of INSERT, UPDATE, DELETE, MOVE, or FETCH, or if no tuples (rows) were affected, 0 is returned.

Returns the status string of the last query command.

cmdtuples()

Alias for cmd_tuples

Invokes the block for each tuple (row) in the result.

Equivalent to res.result.each{ |tuple| … }.

Returns the name of the field (column) corresponding to the index.

  res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable")
  puts res.fieldname(2) => 'jim'
  puts res.fieldname(1) => 'biggles'

Equivalent to res.fields[index].

Returns the index of the field specified by the string name.

  res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable")
  puts res.fieldnum('foo') => 0

Raises an ArgumentError if the specified name isn‘t one of the field names; raises a TypeError if name is not a String.

Returns an array of Strings representing the names of the fields in the result.

  res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable")
  res.fields => [ 'foo' , 'biggles' , 'jim' , 'jam' ]

Returns the data type associated with the given column number.

The integer returned is the internal OID number (in PostgreSQL) of the type. If you have the PostgreSQL source available, you can see the OIDs for every column type in the file src/include/catalog/pg_type.h.

Returns true if the specified value is nil; false otherwise.

Equivalent to res.value(tup_num,field_num)==nil.

Returns the (String) length of the field in bytes.

Equivalent to res.value(tup_num,field_num).length.

Returns the value in tuple number tup_num, field number field_num. (Row tup_num, column field_num.)

Equivalent to res.result[tup_num][field_num] (but faster).

Returns the value in tuple number tup_num, for the field named field_name.

Equivalent to (but faster than) either of:

   res.result[<i>tup_num</i>][ res.fieldnum(<i>field_name</i>) ]
   res.value( <i>tup_num</i>, res.fieldnum(<i>field_name</i>) )

(This method internally calls value as like the second example above; it is slower than using the field index directly.)

Returns the number of fields (columns) in the query result.

Similar to res.result[0].length (but faster).

Returns the number of tuples (rows) in the query result.

Similar to res.result.length (but faster).

num_fields()

Alias for nfields

num_tuples()

Alias for ntuples

Returns the oid.

Returns the size of the field type in bytes. Returns -1 if the field is variable sized.

  res = conn.exec("SELECT myInt, myVarChar50 FROM foo")
  res.size(0) => 4
  res.size(1) => -1

Returns the status of the query. The status value is one of:

  • EMPTY_QUERY
  • COMMAND_OK
  • TUPLES_OK
  • COPY_OUT
  • COPY_IN
type(p1)

Alias for ftype

[Validate]