Getting Null When Trying to Populate ''(empty string)

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Getting Null When Trying to Populate ''(empty string)

Post by loveojha2 »

Hi All,

I am getting a problem regarding NULL..
I am taking ''(empty string) in one of the columns from my source, I am passing the columns from 4 transformers(for lookups) and at last I am writing them to target table.., The corresponding column in the target is not NULLable, But when I run the Job it throws an error saying "can't write NULL for not Nullable column" for that column.

If I hardcode the value ''(empty string) in the last tarnsformer for the column, it accepts the row.

Even if I have checked the column value through isNull function in the stage variables of the last transformer, it shows it as a NOT NULL there also, What is the cause of the Problem..?

Thanks in advance...
WoMaWil
Participant
Posts: 482
Joined: Thu Mar 13, 2003 7:17 am
Location: Amsterdam

Post by WoMaWil »

empty string and NULL is the same! Try to write an empty string directly into you database and you will see that you need not to blame DataStage it is a feature of the database.
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Re: Getting Null When Trying to Populate ''(empty string)

Post by loveojha2 »

Dear WoMaWil

Null means unknown.
Empty string is not unknown.
u can verify the difference by inserting '' in a not null column of a table, it wud accept that, but with null it wud throw an error.
Try this in SQL
create table abc
(
a char primary key not null
)
select * from abc
insert into abc values('')
insert into abc values(null)

U will notice the difference.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What is your target database and what stage are you using to write to it?
-craig

"You can never have too many knives" -- Logan Nine Fingers
amsh76
Charter Member
Charter Member
Posts: 118
Joined: Wed Mar 10, 2004 10:58 pm

Post by amsh76 »

Even I have noticed that starnge behaviour in past, not sure what the reason is. But from what I was able to conclude is that, it happens when you move that data between trasformers somehow that empty string is treated as null.

Try running nulltoempty routine, in the last xformer....and you will see it work fine without any error.

HTH
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Getting Null When Trying to Populate ''(empty string)

Post by chulett »

loveojha2 wrote:Try this in SQL
create table abc
(
a char primary key not null
)
select * from abc
insert into abc values('')
insert into abc values(null)

U will notice the difference.
Just for the record, try this in Oracle and both will fail - which is why I asked about the target database... and probably why WoMaWil made his assertation. Any discussion of database related issues should include a mention of the database in question because of differences like this.

Your issue is, as mentioned, the handling of an empty string as it is passed from transformer to transformer.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If your target is a Sequential File, change the definition of NULL in the Format tab. The default is to replace NULL with "".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

My target is MS SQL Server, if I tried to populate the data through one transformer it works fine...
Post Reply