Postgresql Create ForeignKey with repeated table name in value of ref contrain key I am working on a database which does not contain any foreign key. When i open table I see strange format key because table of parent reference is stored in the value.
exemple
CREATE TABLE foo 
  ( 
  id SERIAL PRIMARY KEY,
  name text
  );

CREATE TABLE bar
  ( 
  id SERIAL PRIMARY KEY,
  foo_id text,
  name text
  );

INSERT INTO foo(&quot;name&quot;)
VALUES ('john');

INSERT INTO bar(&quot;foo_id&quot;,&quot;name&quot;)
VALUES (CONCAT('foo.', 1),'doe');
INSERT INTO bar(&quot;foo_id&quot;,&quot;name&quot;)
VALUES (CONCAT('foo.', 1),'kelly');

Can I create an FK with this type of structure? I have never seen this before
Can I create an FK with this type of structure?

No, you can't create a FK because the value of a FK column must match the value of the referenced PK column. But there is no value foo.1  in the table foo.
That design is horrible. I understand you didn't create that mess, but if you do have the chance to fix it, then do it as soon as possible.