PostgreSQL: should a dictionary primary key be an index or a constraint on the server?

Applies to: a 2013 thread using the FM3 templates against PostgreSQL. Clarion and server versions are not named.

Problem

The dictionary table has a primary key called invoice_id_key. The poster asked what the equivalent on the backend should be, an index or a constraint.

Solution

  1. Create it as a primary key constraint: alter table add constraint pk_invoice primary key (invoice_id);
  2. The longer way with the same effect is a unique index on the column plus a NOT NULL constraint on it.
  3. The poster found his own problem: his legacy conversion app created indexes, not constraints. A new ABC app built with the FM3 templates created the backend as the dictionary says, with a constraint.
  4. If you also define a foreign key constraint, create an index on the same columns, so lookups into the child table have an index.

Caveats

  • The poster could not tell whether the indexes came from his own code or from the FM3 legacy code.
  • Terms as one poster explained them: indexes are physical, take disk space and are maintained by the system. A unique or primary key constraint is a rule, but the system creates an index to enforce it. Foreign key and column constraints are rules only, with no index.

Today (2026)

Likely unchanged; these are PostgreSQL rules, not Clarion ones. The FM3 template behaviour was not re-tested.

Sources: Johan R. (Jul 2013, the question), Jon W., Dennis E. (Jul 2013), Joe T. (Aug 2013) in softvelocity.clarion.databasedrivers.