Informix Error -593: Cannot specify default value for SERIAL or SERIAL8 or BIGSERIAL column.
Cause and resolution
Cannot specify default value for SERIAL or SERIAL8 or BIGSERIAL column.
This CREATE or ALTER TABLE statement specifies that a column has a SERIAL or SERIAL8 or BIGSERIAL data type, but it also has a DEFAULT clause for the column. The database server generates values for a SERIAL or SERIAL8 or BIGSERIAL column each time a row is created, so the DEFAULT clause is meaningless.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-593 fires when a SERIAL, SERIAL8, or BIGSERIAL column is given a DEFAULT clause — per
the official guidance, the server generates these columns' values automatically on every row
insert, so a DEFAULT clause is meaningless for them.
- A
DEFAULTclause added to aSERIAL/SERIAL8/BIGSERIALcolumn definition, per the official guidance — the direct, only cause. - DDL copy-pasted from a non-serial column's definition (which legitimately had a
DEFAULTclause) into a new serial column's definition, without removing the now-meaningless clause. - A misunderstanding of serial columns — expecting to need to specify a starting value via
DEFAULT, when the starting value for a serial column is instead controlled by the initial value given in the type declaration itself (SERIAL(100), for instance).
Solutions / Resolution
- Remove the
DEFAULTclause from the serial column, per the official guidance — the server generates its values automatically; noDEFAULTis needed or accepted. - If a specific starting value is needed, set it in the type declaration itself, not via
DEFAULT:CREATE TABLE orders (order_id SERIAL(1000), status CHAR(10));
Examples
The disallowed attempt
CREATE TABLE orders (order_id SERIAL DEFAULT 1, status CHAR(10));
-- -593: SERIAL columns can't have a DEFAULT clause
Corrected — set the starting value in the type itself
CREATE TABLE orders (order_id SERIAL(1000), status CHAR(10));
Diagnostic Checks
- Scan
SERIAL/SERIAL8/BIGSERIALcolumn definitions for an attachedDEFAULTclause and remove it, moving any intended starting value into the type declaration instead.
Related Errors / Related Topics
- -591 — "Invalid default value for column/variable column-name/variable-name." The more
general
DEFAULT-clause error family this specific serial-column restriction belongs to.
DEFAULT is meaningless on auto-generated serial columns — set a starting value in the type
declaration (SERIAL(n)) instead.