I am trying to join a spatial table with a non-spatial table in Postgresql using the PostGIS extension.
spatial_table:
geom | attribute1 | Key |
foobar | foobar | 1 |
foobar | foobar | 2 |
foobar | foobar | 3 |
foobar | foobar | 4 |
non_spatial_table:
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 |
By NULL I mean empty.
The following code works:
CREATE TABLE joined_table AS
SELECT *
FROM spatial_table
JOIN non_spatial_table ON spatial_table.title_no = non_spatial_table.title_number;
However all the rows in the spatial_table that are not equal to the non_spatial_table are left out of the resultant table.
resultant table:
geom | attribute1 | Key | attribute2 | attribute3 |
foobar | foobar | 1 | foobar | foobar |
foobar | foobar | 4 | foobar | foobar |
I have also tried:
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
However I get the following error:
ERROR: table name "spatial_table" specified more than once SQL state: 42712
Does anyone know how I can achieve this type of join?