There is a table which one value refers to the ID. Those. in the course of work, a very long chain of related records can be built.

How to get True or False depending on whether or not the desired ID is in this thread?

Example table:

CREATE TABLE "message" ( "id" serial NOT NULL, "text" TEXT NOT NULL, "id_mes" INT, CONSTRAINT message_pk PRIMARY KEY ("id") ) WITH ( OIDS=FALSE ); ALTER TABLE "message" ADD CONSTRAINT "message_fk1" FOREIGN KEY ("id_mes") REFERENCES "message"("id"); 

0