Teradata Fastload inserting Null when the field has value empty string ("") - teradata

I am using TTU (fastload) to load data into DB table. Following is the fastld script for data load:
LOGON 127.0.0.1/test,*****;
DATABASE MyDb;
BEGIN LOADING "MyTable"
ERRORFILES error_table_1_607712459, error_table_2_1744826307
CHECKPOINT 0;
SET RECORD VARTEXT DELIMITER ',' QUOTE YES '"' ;
DEFINE in_field_0 (VARCHAR(1000)),in_field_1 (VARCHAR(1000)),
FILE = /tmp/fastload_data_file390318d5-b42d-47d6-8c0f-6822a0bbb6ef.dat;
INSERT INTO "MyTable" ("data","num" ) VALUES (:in_field_0,:in_field_1);
END LOADING;
LOGOFF;
Data file: fastload_data_file390318d5-b42d-47d6-8c0f-6822a0bbb6ef.dat
"Hello World", "1"
"","2"
" ", "3"
null, "4"
After load: MyTable
msg num
Hello World 1
null 2
3
null 4
When the data file has empty string (""), fastload inserting null into the DB. I have tried using TTU 16.20 and 17.00 on Ubuntu OS, behaviour is same across the versions. I am wondering, how to avoid inserting Null into the table. Any suggestions?

Related

Teradata Parallel Transporter DDL Operator - missing { EXTENDED_LITERAL_ CHAR_STRING_LITERAL_ } in Rule: Character String Literal ERROR

What I want to do is check in my database if my table exists, if yes drop it. Here is my .tpt :
DEFINE JOB DELETE_ET_TABLES
DESCRIPTION 'Delete ET tables'
(
DEFINE OPERATOR DDL_OPERATOR
DESCRIPTION 'Teradata Parallel Transporter DDL Operator'
TYPE DDL
ATTRIBUTES
(
varchar TdpId = #TERADATA_TDP,
varchar UserName = #User,
varchar UserPassword = #Pwd
);
APPLY
'SELECT (CASE WHEN TableName = ''Test_Del''
THEN (''DROP TABLE #Table;'')
ELSE NULL
END)
FROM dbc.TablesV WHERE databasename = #Db;' TO OPERATOR(DDL_OPERATOR);
And this is the error message I am getting :
Running "tbuild" command: tbuild -f /$HOME/loaders/test_deleteETTables.tpt -u TERADATA_TDP=$TDP, TERADATA_DATABASE=$DB -L /$LOG/
Teradata Parallel Transporter Version 16.20.00.09 64-Bit
TPT_INFRA: Syntax error at or near line 18 of Job Script File '/$HOME/loaders/test_deleteETTables.tpt':
TPT_INFRA: At "(" missing { EXTENDED_LITERAL_ CHAR_STRING_LITERAL_ } in Rule: Character String Literal
Compilation failed due to errors. Execution Plan was not generated.
Do you have any idea ? I have tried multiple things, such as :
SELECT 1 FROM dbc.TablesV WHERE databasename = #Db AND TABLENAME ='TEST_DEL';
CASE WHEN ACTIVITYCOUNT = 1
THEN (DROP TABLE #Table)
ELSE ( QUIT )
END;
All my variables have been declared. I feel that it is a problem with using single quotes inside que statement but I am not sure and I don't know how to resolve it. Thank you very much for your time.
The solution that Fred recommended me to try in the comments worked just fine :
I think this is due to use of NULL but SELECT is not valid for DDL operator. The recommended way to do this is simply pass a DROP to the operator and tell it to ignore "not found" (and consider that success), i.e. ErrorList='3807'
DESCRIPTION 'Delete ET tables'
(
DEFINE OPERATOR DDL_OPERATOR
DESCRIPTION 'Teradata Parallel Transporter DDL Operator'
TYPE DDL
ATTRIBUTES
(
varchar TdpId = #TERADATA_TDP,
varchar UserName = #USERDB,
varchar UserPassword = #PWD,
VARCHAR ErrorList = '3807'
);
APPLY
('DROP TABLE #TABLENAME')
TO OPERATOR(DDL_OPERATOR);
);```

SQLite Studio - Export database with adding quote to string number

I cannot export my database to a sql file with adding quote to string number. I store code postal number as CHAR[5] but it exports without 'quote'.
eg: What I want my quoting string number '01234' like:
CREATE TABLE codepostal ( code CHAR( 5 ) PRIMARY KEY NOT NULL UNIQUE, name VARCHAR( 70 ) NOT NULL );
INSERT INTO [codepostal] ([code], [name]) VALUES ('01234', 'My_city');
But not 01234 (no quoting):
CREATE TABLE codepostal ( code CHAR( 5 ) PRIMARY KEY NOT NULL UNIQUE, name VARCHAR( 70 ) NOT NULL );
INSERT INTO [codepostal] ([code], [name]) VALUES (01234, 'My_city');
I want to export my db to a sql file then read it to re-create my db somewhere. But since I store code postal "01234" like CHAR[5] and it export without quoting, when I re-create my db > I losts my "0" because it read "01234" but only insert "1234" because my "01234" was no-quoting.
My SQLiteStudio was v2.1.5 and I stored as VARCHAR and TEXT but still no quoting.
Any suggestion can help, thanks. ^_^
SQLiteStudio 2.x.x is obsolete. Use the recent one (at the moment it's 3.0.6, available at its homepage). It will deal with your export correctly.

Convert NULL to Blank TPT Fast Load

Insert into emp values
(:FNAME ,.......
Above Sample Code from TPT works fine.
I want to convert null values in flatfile to blank while loading
insert into emp values ( COALESCE(:Fname,' '),.... -- Throws ERROR
TPT_INFRA: TPT04046: Error: Line 193 of Job Script File 'tpscript4.txt': Adjacen
t quoted strings must be separated by the
concatenation operator: '||'.
Job script preprocessing failed.
insert into emp Values ( case when :Fname is null then ' ' else :Fname End,... --Throws Error
Teradata Parallel Transporter Version 13.10.00.02
TPT_INFRA: TPT04046: Error: Line 191 of Job Script File 'tpscript4.txt': Adjacen
t quoted strings must be separated by the
concatenation operator: '||'.
Job script preprocessing failed.
Job terminated with status 8.
When used Case when in Select oerator for fastload:
TO OPERATOR (UPDATE_OPERATOR[2])
SELECT case when FNAME is null then ' ' else FNAME,LNAME,....
FROM OPERATOR (FILE_READER[2]);
ERROR:
TPT_INFRA: Syntax error at or near line 249 of Job Script File 'tpscript4.txt':
TPT_INFRA: At "SELECT" missing SEMICOL_ in Rule: Job Definition Body
Compilation failed due to errors. Execution Plan was not generated.
Job script compilation failed.
Job terminated with status 8.
Note: with out the case in select it is working fine ,
APPLY('insert into emp values ( COALESCE(:Fname,'' ''),....') Worked with Mload
and
SELECT CASE WHEN Fname IS NULL THEN ' ' ELSE Fname END AS Fname,... FROM OPERATOR worked with Fload
You didn't specify which error is returned, i assume it's related to the single quotes. Your INSERT is probably within an APPLY('INSERT ....;') you might try two single quotes to get one quote in a string:
APPLY('insert into emp values ( COALESCE(:Fname,'' ''),....')
Or do it in the SELECT (COALESCE is not supported here):
SELECT
CASE WHEN Fname IS NULL THEN ' ' ELSE Fname END AS Fname,
...
FROM OPERATOR

load csv file into multiple Oracle tables

I have created a control file using TOADs SQL* Loader Wizard. I have used specified following two tables to load the data but the after running the data has only loaded into one table and a dsc file is generated. Below is the control file I am using:
LOAD DATA
INFILE '\\ANKH\Logs\production export 2012-12-06\BS7666CSV_001.csv'
BADFILE '\\ANKH\Logs\production export 2012-12-06\BS7666CSV_001.bad'
DISCARDFILE '\\ANKH\Logs\production export 2012-12-06\BS7666CSV_001.dsc'
INTO TABLE "STREET"
TRUNCATE
WHEN (record_id = '11')
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' AND '"'
(RECORD_ID,
CHANGE_TYPE,
PRO_ORDER,
USRN,
TYPE,
AUTH_CODE,
STATE,
STATE_DATE,
SURFACE,
CLASS,
VERSION,
START_DATE,
END_DATE,
LAST_UPDATE_DATE,
ENTRY_DATE,
START_X_COORD,
START_Y_COORD,
END_X_COORD,
END_Y_COORD,
TOLERANCE)
INTO TABLE "STREET_DESCRIPTOR"
TRUNCATE
WHEN (record_id = '15')
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' AND '"'
(RECORD_ID,
CHANGE_TYPE,
PRO_ORDER,
USRN,
DESCRIPTOR,
LOCALITY,
TOWN,
ADMIN_AREA,
LANGUAGE)
I figured it out that I was missing the keyword POSITION(1) in my second INTO TABLE statement to reset the pointer to the beginning of the record.

How to get trailing spaces from varchar column in Informix using ODBC

I cannot get trailing spaces from varchar column in Informix database.
I created test table, filled it with field with some trailing spaces,
but they are not returned by SELECT while it seems they are stored in db.
CREATE TABLE tmptable (txt varchar(240));
INSERT INTO tmptable (txt) VALUES ('123 ');
SELECT txt, txt || '***', LENGTH(txt) FROM tmptable;
And I got fields:
1: '123' : no trailing spaces!!!
2: '123 ***' : it seems that spaces are stored!!!
3: 3 : LENGTH() do not count trailing spaces!!!
Other databases I tested: Oracle and PostgreSQL return varchar fields
with trailing spaces. I tried RPAD() but with no success. Is there any way to get
trailing spaces?
Server: IBM Informix Dynamic Server Version 11.50.TC2DE
Client: tested with both ISA (no spaces in HTML page source) and ODBC driver 3.50.TC3DE
EDIT
Simple Python test program (tested with ActivePytnon 2.6 on Windows, you must change connection string in the last lines)
import odbc
def test_varchar(db_alias, dbname):
print
print
arr = db_alias.split('/')
print '%s %s' % (arr[0], dbname)
print '--------------'
connection = odbc.odbc(db_alias)
try:
cursor = connection.cursor()
cursor.execute("DELETE FROM tmptable;")
cursor.execute("INSERT INTO tmptable (txt) VALUES (' %s ')" % (dbname))
#cursor.commit()
cursor.execute("SELECT txt, txt || '***', LENGTH(txt) FROM tmptable;")
for row in cursor.fetchall():
print '[%s]\t[%s]\t[%s]' % (row[0], row[1], row[2])
finally:
connection.close()
#test_varchar('database/user/passwd', 'DBproducer')
test_varchar('oracledb/usr/passwd', 'Oracle ')
test_varchar('informixdb/usr/passwd', 'Informix ')
test_varchar('postgresqldb/usr/passwd', 'PostgreSQL')
And results:
c:\tools\pyscripts\scripts\db_examples>test_odbc.py
oracledb Oracle
--------------
[ Oracle ] [ Oracle ***] [16]
informixdb Informix
--------------
[ Informix] [ Informix ***] [11]
postgresqldb PostgreSQL
--------------
[ PostgreSQL ] [ PostgreSQL ***] [16]
Similar program in Jython using JDBC:
works (do not trim trailing spaces)
with native JDBC driver
doesn't work
(trim trailing spacec) with JDBC-ODBC
bridge
Source:
# for Jython 2.5 invoke with --verify
# beacuse of bug: http://bugs.jython.org/issue1127
import sys
from com.ziclix.python.sql import zxJDBC
def test_varchar(driver, db_url, usr, passwd):
arr = db_url.split(':', 2)
dbname = arr[1]
if dbname == 'odbc':
dbname = db_url
print "\n\n%s\n--------------" % (dbname)
try:
connection = zxJDBC.connect(db_url, usr, passwd, driver)
except:
ex = sys.exc_info()
s = 'Exception: %s: %s\n%s' % (ex[0], ex[1], db_url)
print s
return
cursor = connection.cursor()
cursor.execute("SELECT txt, txt || '***', LENGTH(txt) FROM tmptable")
for row in cursor.fetchall():
print '[%s]\t[%s]\t[%s]' % (row[0], row[1], row[2])
#test_varchar(driver, db_url, usr, passwd)
test_varchar("org.postgresql.Driver", 'jdbc:postgresql://127.0.0.1/pg_testdb', 'postgres', 'postgres')
test_varchar("oracle.jdbc.driver.OracleDriver", 'jdbc:oracle:oci:#MNTEST', 'user', 'passwd')
test_varchar("com.informix.jdbc.IfxDriver", 'jdbc:informix-sqli://127:0:0:1:9088/test_td:informixserver=ol_mn;DB_LOCALE=pl_PL.CP1250;CLIENT_LOCALE=pl_PL.CP1250;charSet=CP1250', 'user', 'passwd')
# db_url = jdbc:odbc:[ODBC source name]
test_varchar("sun.jdbc.odbc.JdbcOdbcDriver", 'jdbc:odbc:inf_test_db_odbc', 'user', 'passwd')
test_varchar("sun.jdbc.odbc.JdbcOdbcDriver", 'jdbc:odbc:ora_testdb_odbc', 'user', 'passwd')
test_varchar("sun.jdbc.odbc.JdbcOdbcDriver", 'jdbc:odbc:pg_testdb_odbc', 'postgres', 'postgres')
Results (for Informix only):
C:\tools\pyscripts\scripts\db_examples>jython --verify test_jdbc2.py
informix-sqli
--------------
[ Informix ] [ Informix ***] [11]
jdbc:odbc:inf_test_db_odbc
--------------
[ Informix] [ Informix ***] [11]
In ESQL/C, it is most certainly possible to get the trailing spaces from a VARCHAR column; my SQLCMD program (available from the IIUG Software Archive) does it. But you have to be extremely careful to use the correct type for the variables that hold the result. By default, the various char types are treated as CHAR rather than VARCHAR, and the libraries strip trailing blanks from CHAR values unless you direct otherwise (and blank pad to full length when you do direct otherwise).
Regarding ISA: I don't know how you established what it returns. I'm not altogether surprised that it loses the trailing blanks. Similar comments would apply to DB-Access.
Regarding ODBC: can you show the code, please, because although it is possible that there's a bug in the code (thank you for including the version information - it helps, and reassures me you are effectively up-to-date with your system), it is more likely that there is something up with the code you wrote to use it.
Regarding LENGTH(): it is defined to remove trailing blanks before calculating the length; it always treats its argument as if it was a CHAR value rather than as a VARCHAR value.
Taking your code and using SQLCMD:
Black JL: sqlcmd -d stores - <<!
> CREATE TABLE tmptable (txt varchar(240));
> INSERT INTO tmptable (txt) VALUES ('123 ');
> SELECT txt, txt || '***', LENGTH(txt) FROM tmptable;
> !
123 |123 ***|3
Black JL:
'Black JL:' is my Unix prompt on machine 'black'; as you can see, I got the trailing blanks OK (but I wrote SQLCMD about 20 years ago, now, in part because DB-Access, or rather its predecessor ISQL, didn't do things carefully enough for my purposes).
For anyone that doesn't feel like guessing what the "correct type" is, I've gotten my esql program to work by specifying a "lvarchar" type. (at least one version of the esql/c guide implies that "varchar" should work, but it didn't for me)

Resources