Storing R objects in database tables
The Netezza R library allows you to store serialized versions of your objects in database
tables. As Netezza does not support large objects (LOBS), objects are stored across several database
rows. To make management of such objects easier, the nzr
package introduces the
object class nz.list
.
nz.list
is aligned with lists in R, although objects are stored remotely instead
of locally. An nz.list
object is a reference to a specially formatted database
table.
To create an
nz.list
, you can use the following
command:nzl <- nz.list("MYNEWLIST",createTable=T, indexType="character");
This
command creates a table MYNEWLIST
and a local stub object nzl
. The
indexType character parameter indicates that the index column for the list is
represented by varchar in the database. The indexType integer would use an
integer column for this purpose.Objects can be stored to the remote list by using the [] and $
operators.
#Store an object
nzl['myKey'] ← 1:100000
nzl$myKey ← 1:100000
#Read an object
nzl['myKey']
nzl$myKey
#Delete an object
nzl['myKey'] ← NULL
nzl$myKey ← NULL
Note: The names function returns all the keys in a list; the length
function returns the length of a list.
The following arguments are used with the
nz.list
constructor:- tableName
- Specifies the name of the database table containing the list. This can be an existing table or a new one.
- createTable
- Optional. If
TRUE
, a new table is created if it does not yet exist. - indexType
- If a new table is created, it indicates the type of index to use, integer or character.