【发布时间】:2012-10-09 21:51:30
【问题描述】:
例如:假设我创建了 2 个模式和 4 个表
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);
我要查找的伪代码:选择所有引用 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,我的回答没有用吗?这个查询是“喜欢”
select all tables where b.main.id is referenced;
标签: sql postgresql