Using database sequence

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Using database sequence

Post by mydsworld »

I have a DB2 sequence created in database.I want that to be used in my target DB2 API stage (like NEXTVAL FOR MYSCHEMA.X_SEQ).Can I do that?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Yes. But you will need user-defined SQL, and you will need NOT to pass the key column value from DataStage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Post by mydsworld »

By 'User defined SQL', do you mean Custom SQL, then thats what I am trying.

Seq File -> Trnsfrm -> DB2 API (table TEST1)

TEST1 table contains columns id,name
I am generatng id through DB2 sequence and need to bring name from input.

Will my custom SQL inside DB2 API look like this

insert into MYSCHEMA.TEST1 values(NEXTVAL FOR MYSCHEMMA.X_SEQ,?)

But then again 1st column is showing unmapped in Transformer.
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

Delete the column id and use the below query.

Code: Select all

INSERT INTO MYSCHEMA.TEST1 (id,name) VALUES (NEXTVAL FOR MYSCHEMMA.X_SEQ,:1)
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The Transformer stage output link must have only one column (name). It must not output the id column. That way, name will align with the :1 parameter marker (the first parameter).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Post by mydsworld »

Ray & Narasimha,

I did the way you mentioned.Transformer output only name (and not id).Within DB2 API, I am generating the id using the sequence

INSERT INTO MYSCHEMA.TEST1 (id,name) VALUES (NEXTVAL FOR MYSCHEMMA.X_SEQ,:1)

But since Column definition in DB2 API contains only 'name', so writing the above SQL gives mismatch of metadata.

DB2_UDB_API_2,0: Fatal Error: Fatal: This SQL statement did not contain the same number of parameters as columns on this link. This usually happens with user-defined SQL.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sounds like you still have both columns in the output link.
-craig

"You can never have too many knives" -- Logan Nine Fingers
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Post by mydsworld »

No, I have just one column name defined in the output link. Still I am getting the same (metadata mismatch) error. Because in SQL I am retrieving 2 columns whereas in column definition I have only 1 column.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Then perhaps that's a PX restriction, what you've done would work just fine in Server. It matches the columns in the link to the parameter markers in your sql, it doesn't give a hoot how many column names you mention.
-craig

"You can never have too many knives" -- Logan Nine Fingers
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

never used DB2, but for this situation with oracle stage, i have written a before insert trigger on the target table. in the mapping i default the input to 1,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't have DB2 here but don't recall it using numbered parameter markers, I thought that was strictly an Oracle thing. Are you sure that :1 shouldn't be a ? instead? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply