【发布时间】:2018-06-14 20:35:56
【问题描述】:
我正在尝试使用 PostGIS 扩展将空间表与 Postgresql 中的非空间表连接起来。
空间表:
geom | attribute1 | Key |
foobar | foobar | 1 |
foobar | foobar | 2 |
foobar | foobar | 3 |
foobar | foobar | 4 |
非空间表:
attribute2 | attribute3 | Key |
foobar | foobar | 1 |
foobar | foobar | 4 |
joined_table:
geom | attribute1 | Key | attribute2 | attribute3 |
foobar | foobar | 1 | foobar | foobar |
foobar | foobar | 2 | NULL | NULL |
foobar | foobar | 3 | NULL | NULL |
foobar | foobar | 4 | foobar | foobar |
NULL 我的意思是空的。
以下代码有效:
CREATE TABLE joined_table AS
SELECT *
FROM spatial_table
JOIN non_spatial_table ON spatial_table.title_no = non_spatial_table.title_number;
但是,spatial_table 中不等于 non_spatial_table 的所有行都被排除在结果表之外。
结果表:
geom | attribute1 | Key | attribute2 | attribute3 |
foobar | foobar | 1 | foobar | foobar |
foobar | foobar | 4 | foobar | foobar |
我也试过了:
ALTER TABLE spatial_table
ADD COLUMN title_number varchar,
ADD COLUMN tenure varchar
UPDATE spatial_table
SET title_number = non_spatial_table.title_number
FROM spatial_table INNER JOIN non_spatial_table ON spatial_table.title_no = non_spatial_table.title_number
但是我收到以下错误:
ERROR: table name "spatial_table" specified more than once SQL state: 42712
有谁知道我怎样才能实现这种类型的加入?
【问题讨论】:
-
为表格添加一些别名,并参考这些。 , 并添加一些分号。另外:您不必在 FROM 子句中重复 target 表。
标签: postgresql join sql-update postgis