Search code examples
sqlfirebird

RDB$NULL_FLAG is null for all columns


I'm trying to run a query to extract metadata of all columns in Firebird. Here's what it looks like:

select
      f.RDB$RELATION_NAME as tableName,
      f.RDB$FIELD_NAME name,
      fd.RDB$FIELD_TYPE type,
      fd.RDB$FIELD_SCALE scale,
      fd.RDB$FIELD_SUB_TYPE subtype,
      fd.RDB$DIMENSIONS dimensions,
      fd.RDB$NULL_FLAG notNull,
      fd.RDB$FIELD_PRECISION precision
from rdb$relation_fields f
join rdb$relations r on f.RDB$RELATION_NAME = r. RDB$RELATION_NAME
join RDB$FIELDS fd on fd.RDB$FIELD_NAME = f.RDB$FIELD_SOURCE
where f.RDB$UPDATE_FLAG = 1
  and r.RDB$RELATION_TYPE = 0
  and coalesce(r.RDB$SYSTEM_FLAG, 0) = 0

For the most part, it works fine. But for whatever reason, every single result gives null in the fd.RDB$NULL_FLAG column. According to the documentation, this value should be null if a column is nullable, or 1 if it is not. (It should go without saying that I do, in fact, have some NOT NULL columns in my database!)

Any idea what's going wrong, and how I can get correct reporting of the nullability status of my columns?


Solution

  • You should also check f.RDB$NULL_FLAG which overrides domain definition.