Run the stringpad UDFs

After you create the C++ programs that contain your SPUPad calls, you compile them by using nzudxcompile and register them on the Netezza Performance Server system. For an example of the CREATE [OR REPLACE] FUNCTION commands to register these sample UDFs, see The string_pad_create.cpp sample program and The string_pad_get.cpp sample program. These functions can easily be saved in one C++ program; after you compile the program, you would use the CREATE [OR REPLACE] FUNCTION command to register each of the functions as separate UDFs.

After you compile and register the UDFs, you can run them. For example, the following sequence of commands that is entered at the nzsql prompt show how these functions process the data. The commands are processed within a BEGIN/COMMIT transaction block so that the SPUPad still exists for the string_pad_get function.

Note: The one_dslice table has one row and thus is saved on only one dataslice. Its content has no bearing on the string processing in this example, but its presence and content cause the UDF to create the SPUPad on the S-Blade that manages the dataslice where the single row of the table is. For more information about how the table can affect the operation of the SPUPad, see Tables and SPUPad operations.
MYDB.SCHEMA(MYUSER)=> BEGIN TRANSACTION;
BEGIN
MYDB.SCHEMA(MYUSER)=> SELECT string_pad_create(10, 'netezza') FROM 
one_dslice;
 STRING_PAD_CREATE
-------------------
 t
(1 row)

MYDB.SCHEMA(MYUSER)=> SELECT string_pad_get(0) FROM one_dslice;
 STRING_PAD_GET
----------------
 n
(1 row)

MYDB.SCHEMA(MYUSER)=> SELECT string_pad_get(1) FROM one_dslice;
 STRING_PAD_GET
----------------
 e
(1 row)

MYDB.SCHEMA(MYUSER)=> SELECT string_pad_get(2) FROM one_dslice;
 STRING_PAD_GET
----------------
 t
(1 row)

MYDB.SCHEMA(MYUSER)=> COMMIT; 
COMMIT
If you run these functions as single select statements, the first function (string_pad_create) would run, create the SPUPad and the character array, and then exit. When the function returns, the Netezza Performance Server system automatically cleans up the SPUPad and frees the memory. If you then run string_pad_get in a single select, you would see the following error because the SPUPad no longer exists:
MYDB.SCHEMA(MYUSER)=> select string_pad_get(0) from one_dslice;
ERROR: Pad does not exist