addDimensionForeignKey

lsst.daf.butler.addDimensionForeignKey(tableSpec: ddl.TableSpec, dimension: Dimension, *, primaryKey: bool, nullable: bool = False, constraint: bool = True) ddl.FieldSpec

Add a field and possibly a foreign key to a table specification.

The field will reference the table for the given Dimension.

Parameters:
tableSpecddl.TableSpec

Specification the field and foreign key are to be added to.

dimensionDimension

Dimension to be referenced. If this dimension has required dependencies, those must have already been added to the table. A field will be added that correspond to this dimension’s primary key, and a foreign key constraint will be added only if the dimension is associated with a table of its own.

primaryKeybool

If True, the new field will be added as part of a compound primary key for the table.

nullablebool, optional

If False (default) the new field will be added with a NOT NULL constraint.

constraintbool

If False (True is default), just add the field, not the foreign key constraint.

Returns:
fieldSpecddl.FieldSpec

Specification for the field just added.