Script example for loading data by using the fixed-length format
You can use a script to load data by using the fixed-length format.
A sample script follows:
LOGDIR="/tmp"
DIR="/tmp"
NZSQL="nzsql -db test -c"
function CreateDb()
{
nzsql -c "create database test"
}
function CleanUp()
{
$NZSQL "drop table textDelim_tbl"
$NZSQL "drop table textFixed_tbl"
}
function CreateTable()
{
$NZSQL "create table textDelim_tbl(col1 int, col2 char(10), col3
date)"
$NZSQL "create table textFixed_tbl(col1 int, col2 char(10), col3
date)"
}
function CreateDataFile()
{
# Create text delimited data file
cat > $DIR/delimData << EOF
1|Customer|12/7/2011
2|Netezza|02/16/2010
EOF
# Create text fixed data file
cat > $DIR/fixedData << EOF
1HelloWorld2011-12-07
2Netezza 2010-02-16
EOF
}
function LoadData()
{
# nzload using text format
nzload -t textDelim_tbl -df $DIR/delimData -db test -outputDir
$LOGDIR -delim '|' -dateStyle MDY -dateDelim '/'
#nzload using fixed format
nzload -t textFixed_tbl -df $DIR/fixedData -db test -outputDir
$LOGDIR -format fixed -layout "col1 int bytes 1, col2 char(10) bytes
10, col3 date YMD '-' bytes 10"
}
function UnloadData()
{
$NZSQL "insert into textDelim_tbl select * from external
'$DIR/delimData' using (Delimiter '|' DateStyle 'MDY' DateDelim '/');"
}
CreateDb
CleanUp
CreateTable
CreateDataFile
LoadData
UnloadData