L
L
Leonid2022-01-07 21:48:49
PostgreSQL
Leonid, 2022-01-07 21:48:49

How to change reference to another table in PostgreSQL?

Hello!
I have a table with columns:

create table  app_public.category (
    id uuid primary key default gen_random_uuid(),
    parent_id uuid default null
);


how do i change the parent_id column to the following value:
parent_id uuid references app_public.category on delete cascade
?
This column is currently empty, so there is no need to save the old values..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2022-01-08
@galaxy

ALTER TABLE app_public.category
ADD CONSTRAINT blah
FOREIGN KEY (parent_id) references app_public.category (id)
on delete cascade;

Or DROP COLUMN + ADD COLUMN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question