How to find out whether a row is currently referenced by a row in a different table?

From: <slapo(at)centrum(dot)sk>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: How to find out whether a row is currently referenced by a row in a different table?
Date: 2010-07-01 12:29:03
Message-ID: 201007011429.16276@centrum.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello everyone,

does anyone know how to find out whether a row is currently referenced by a row in a different table? They are bound together by a foreign key constraint.
The reason why I would like to know this is that I would like to be able to delete rows only if they aren't used anywhere. If this can't be done by a single query, does anyone have such a function they could share or at least a few hints where I could look for more information?

It occurred to me that I could create a function that would query a system table for all references to the table the row would be deleted from and then scan tables that refer to that one, but I was hoping there would be a simpler and maybe a more efficient way to do this.

Thanks in advance.

Peter

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2010-07-01 15:07:10 Re: How to find out whether a row is currently referenced by a row in a different table?
Previous Message Thom Brown 2010-07-01 08:31:10 Re: null vs empty string