Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8230485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:09:11+00:00 2026-06-07T17:09:11+00:00

My webApp works with 2 DataBase servers Informix and DB2 (v9.5 run on localhost),

  • 0

My webApp works with 2 DataBase servers Informix and DB2 (v9.5 run on localhost), when i work with informix DB i can insert null into a primary key (informix DB handle it and accepts nulls and auto increment the column (Serial8)) but when i switched to use DB2 it doesn’t work and this error arrises (DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2, TABLEID=280, COLNO=0, DRIVER=3.50.152 , sqlCode = -407) it looks like DB2 doesn’t allow nulls for primary keys (BigInt) ,so how to enforce DB2 to allow nulls for primary key? in a word i want DB2 to allow me insert nulls for this column and auto increment the values in it each time i make an insert

here’s the script to create the table:

CREATE TABLE corr.CORRESPONDENCE  (
this is the specified col---->CORR_ID BIGINT NOT NULL,
    CORR_NAME VARCHAR(255) NOT NULL,
    CORR_NO VARCHAR(255),
    CREATE_DATE_TIME TIMESTAMP NOT NULL,
    DELIVERY_DATE_TIME DATE,
    NO_OF_ATTACH INTEGER,
    SITE_ID VARCHAR(20),
    DELIVERY_ID VARCHAR(20),
    CREATE_USER BIGINT NOT NULL,
    SECURITY_ID BIGINT,
    DELIVERY_BY VARCHAR(20),
    WORKFLOW_ID BIGINT
)
DATA CAPTURE NONE ;

ALTER TABLE corr.correspondence ADD CONSTRAINT u143_159 PRIMARY KEY 
(corr_id)  ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:09:13+00:00Added an answer on June 7, 2026 at 5:09 pm

    Which version of Informix? What is the schema of the table? What is the INSERT statement? Which API are you using to access Informix? Which platform is the client code running on? Which platform is the database server running on?

    I’m not convinced that you can insert nulls into a SERIAL-like column in Informix. Do you have a primary key constraint on your table, or just a SERIAL8 column that has no NOT NULL and no PRIMARY KEY constraint on it? You cannot insert NULL directly into a SERIAL8 column (nor, by inference, into a SERIAL or BIGSERIAL column).

    Demonstration (using a development version of Informix 11.70.FC6 on RHEL 5 Linux x86/64; client is ESQL/C based, and both client and server are on the same machine):

    SQL[1910]: begin;
    SQL[1911]: create table t1(s8 serial8 not null, v1 char(8) not null);
    SQL[1912]: insert into t1(s8, v1) values(null, "works?");
    SQL -391: Cannot insert a null into column (t1.s8).
    SQLSTATE: 23000 at /dev/stdin:6
    SQL[1913]: rollback;
    SQL[1914]: begin;
    SQL[1915]: create table t1(s8 serial8 primary key, v1 char(8) not null);
    SQL[1916]: insert into t1(s8, v1) values(null, "works?");
    SQL -703: Primary key on table (t1) has a field with a null key value.
    SQLSTATE: IX000 at <<temp>>:2
    SQL[1917]: rollback;
    SQL[1918]: create table t1(s8 serial8, v1 char(8) not null);
    SQL[1919]: insert into t1(s8, v1) values(null, "works?");
    SQL -391: Cannot insert a null into column (t1.s8).
    SQLSTATE: 23000 at <<temp>>:2
    SQL[1920]: drop table t1;
    SQL[1921]:
    

    And bother, I forgot to restart the transaction after 1917!

    This is behaving exactly as it should; you should not be allowed to insert a NULL into a SERIAL8 (or SERIAL, or BIGSERIAL) column. You can insert zeroes into those columns and a new value will be allocated automatically. But you cannot, and should not be able to, insert a NULL into the column.

    DB2 is likewise correct in rejecting attempts to insert NULL into any of the columns in a primary key. It simply is not something you should be allowed to do.


    Answering comments

    Frank Computer commented:

    Strange, I was under the impression that when loading data into a table with a SERIAL column, if I did not supply a value for the SERIAL column, it would convert the NULL to a zero during the insert, as if the loaded data contained a zero?

    Also, with ISQL Perform, when I insert a new row into a table containing a SERIAL column, I don’t supply a value for the SERIAL column, yet Perform displays a zero (0) and after hitting Escape, it converts it to the next highest INT value!

    My immediate response was:

    • LOAD is done by a complex sub-routine in the client that munges the data, and it could/would deal with NULL for SERIAL columns.

    • With ISQL, Perform explicitly enforces 0 during data entry and reports back on the inserted value; again, the client-side code is preventing the error.

    This is why it is important to know what is in use to demonstrate problems or features. Now I’ve got to make a LOAD and NULL demo using DB-Access…I don’t think my SQLCMD program fixes up NULL for SERIAL columns during LOAD (or, if it does, I made that hack a long, long time ago).

    Testing DB-Access (from IDS 11.70.FC2 on Mac OS X 10.7.4, this time), with:

    xx.unl

    |data for row 1|1|
    |data for row 2|2|
    

    xx.sql

    BEGIN;
    CREATE TABLE load_null(s8 SERIAL8 PRIMARY KEY, v32 VARCHAR(32) NOT NULL, i INTEGER NOT NULL);
    LOAD FROM "xx.unl" INSERT INTO load_null;
    ROLLBACK;
    

    DB-Access Output

    $ dbaccess stores xx
    
    Database selected.
    
    
    Started transaction.
    
    
    Table created.
    
    
      703: Primary key on table (load_null) has a field with a null key value.
    
      847: Error in load file line 1.
    Error in line 3
    Near character position 41
    
    Transaction rolled back.
    
    
    Database closed.
    
    $
    

    This does not lend support to the ‘DB-Access maps NULL for a SERIAL8 column into a zero’ hypothesis. This is SERIAL8 rather than plain SERIAL, but when I changed SERIAL8 into SERIAL, I got the same error; ditto with BIGSERIAL. I don’t have ISQL as opposed to DB-Access on the Mac (laziness; I did the port a while ago, but didn’t install it as it was not official, and it is not GA), and it is possible that there’s a difference between the two LOAD commands, but relatively unlikely.

    Testing SQLCMD on the same SQL and data (unload) files, I get the same error message.

    I am more than ever unconvinced by the claim that it is possible to insert NULL values into a primary key column with Informix.


    More comments and explanations

    Although I know LOAD is not an Informix SQL native statement, I assumed it was added to the SE (Standard Engine) and OL (OnLine) engines?

    No; the LOAD statement is handled by code in client programs: DB-Access, ISQL, I4GL, DB-Load, DB-Import. In each case, the statement is recognized and parsed by the client, converted into a suitable INSERT statement that is prepared, then the client reads and parses the data file, and sends the data to the server one row at a time (logically; actually, there’s an INSERT cursor involved which gives you batch operation on insertions).

    Or does LOAD statement actually call the DBLOAD.EXE utility in SE/OL or onload.exe?

    No: the LOAD statement does not involve DB-Load, nor does it involve ON-Load.

    Is the source for SQLCMD available? If so, can I dump dbaccess and replace it with a stripped down version of SQLCMD?

    Yes. It is available from the IIUG (International Informix User Group) Software Archive. The version available there (87.02) is close to current (I’m using 87.06, but I’m not quite ready to release that to the rest of the world, and it’ll be 88.00 when it is released). I don’t support it on Windows, simply because I find Windows too hostile a development environment. It has, on occasion, been made to work on Windows, though. My last attempt stopped when I found Microsoft promulgating the ‘Safe C Library’ routines, but the routines they provide are not the same as the ones in the standard TR 27341. I gave up again at that point.

    I just confirmed that my ole SE-4.10 clunker accepts NULL values for SERIAL columns when inserting a load file with LOAD.

    OK. You couldn’t specify PRIMARY KEY constraints in that version (those arrived with 5.00, I’m almost certain), but you could create unique indexes on SERIAL columns, etc. To the extent that it is a bug, it has presumably been fixed. It might or might not be fixed in SE 7.26; I’d expect it to be, but haven’t demonstrated that it is. It is fixed in 11.70; my tests above demonstrate that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java EE webapp that works perfectly when I run it on
I have developed a web application using Netbeans 6.7 and Ant. The webapp works,
I have the httphandler on shared webhosting. It works. The httphandler webapp (virtual) dir
I'm currently working on a small webapp where I work. I've created this for
I am migrating a classic ASP web app to new servers. The database back
i'm developing a webapp for iphone/ipod and using the client's side database. I want
I am basically a newbie whose starting work on a new webapp. The webapp
Having in mind that each webapp has its own separate database (but all databases
I'm writing a webapp which uses an embedded instance of RavenDB as its database.
On my Unix web server, I have two MySQL database servers running. One on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.