例如:我说,我有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