I’m trying to figure out how to programmatically determine whether or not the columns of a given table are nullable in an Informix database. I’ve figured out how to get the column data for any given data, but it doesn’t seem like these results are useful for my purposes; that is, there doesn’t seem to be an attribute that indicates whether or not the column accepts null.
Do I need to join to another sys__ table or something of that sort?
The query I’m currently using:
SELECT *
FROM "informix".syscolumns
WHERE tabid = (SELECT tabid FROM "informix".systables WHERE tabname = 'myTable');
This returns a table with colname, tabid, colno, coltype, collength, colmin, colmax, extended_id, seclabelid, and colattr. Perhaps the nullable property is something in the coltype… ?
Quote from the manual:
The
coltypecodes listed on the previous page can be incremented by bitmaps showing the following features of the column.Then on the next page:
Similarly, the coltype value is incremented by 256 if the column does not allow NULL values. To determine the data type for such columns, subtract 256 from the value and evaluate the remainder, based on the possible coltype values. For example, if the coltype value is 262, subtracting 256 leaves a remainder of 6, indicating that the column has a SERIAL data type