例如:我說,我有2種模式和選擇所有引用的表
create table a.foo(
id integer primary key,
val integer);
create table b.main(
id serial primary key,
val integer references a.foo(id));
create table b.foo(
k integer primary key references b.main(id),
v timestamp with time zone);
create table b.bar(
k integer primary key references b.main(id),
v timestamp with time zone);
創建4個表
的僞什麼我在尋找代碼:選擇b.main.id被引用的所有表;
結果會是什麼樣子:
b.main.id | b.main.val | b.foo.k | b.foo.v | b.bar.k | b.bar.v
1 1 1 TimeStamp 1 TimeStamp
2 1 2 .... 2 ....
現在我已經實現了這個查詢爲:
select * from b.main,
(select *
from b.foo,
(select * from b.bar where b.bar.v > somedate) as morebar
where b.bar.k = b.foo.k) as morefoo
where b.main.id = b.foo.k;
回到問題。 Postgres中是否有一項功能允許我們在引用主鍵的所有表上執行選擇?在我的情況下,所有引用b.main.id的表
我已經通過Postgresql文檔搜索,但還沒有找到我在找什麼。建議?
嗨@fbynite,沒有工作我的回答?這個查詢是「like」'選擇引用b.main.id的所有表;' – doctore