Skip to content

GNNTable.set_foreign_key()

Set an existing column in the GNN table as a foreign key.

NameTypeDescriptionOptional
foreign_keyForeignKeyThe foreign key definition to apply.No

Raises ValueError if the referenced column does not exist in the GNN table.

from relationalai_gnns import GNNTable, ForeignKey
# At first add one foreign key referencing TableWithCKey1.Id1,
# where TableWithCKey1 is the name of the "DATABASE.SCHEMA.TABLE_WITH_CKEY_1" table defined before,
# and Id1 is its candidate key column.
table_with_foreign_keys = GNNTable(
connector=connector,
name="TableWithFKeys",
source="DATABASE.SCHEMA.TABLE_WITH_FKEYS",
type="node",
foreign_keys=[ForeignKey(column_name="Id1", link_to="TableWithCKey1.Id1")]
)
# Then add a second foreign key referencing TableWithCKey2.Id2,
# where TableWithCKey2 is the name of the "DATABASE.SCHEMA.TABLE_WITH_CKEY_2" table defined before,
# and Id2 is its candidate key column.
table_with_foreign_keys.set_foreign_key(ForeignKey(column_name="Id2", link_to="TableWithCKey2.Id2"))