Skip to content

Foreign key snippets

SQL snippets to add Postgres foreign keys for Whalesync, plus the _fk naming workaround that lets a uuid[] array column sync Airtable linked records.

Whalesync supports foreign keys. After creating your tables, you can designate a foreign key and then point it to another table's primary key.

ALTER TABLE public."Table"
ADD CONSTRAINT table_category_fkey
FOREIGN KEY ("category")
REFERENCES categories("name");

In the example above we are adding to a table called "Table" to an existing column called "category" a foreign key pointing to column called "name" in a table called "categories". The example creates the foreign key relationship, it does not create any tables and columns, they must already all exist.