It is my first question in this forum.
I wrote this code, but it is incorrect and I can't find a problem.
I have 2 tables: sciana (gid,id,geom)
and sciana1(gid,id,geom)
.
If table sciana
is empty I want to sciana.id = sciana.gid
, but if sciana
is not null I want to find max(sciana.id) + sciana1.gid
UPDATE sciana1
SET id =
CASE
WHEN sciana.gid IS NULL THEN
id = sciana1.gid
WHEN sciana.gid IS NOT NULL THEN
(SELECT max(sciana.id)+sciana1.gid
FROM sciana )
END;
First example:
`sciana` IS EMPTY, so after the update `sciana1` looks like
1,1,geom1
2,2,geom2
...
Second example:
sciana
IS NOT EMPTY
1,1,geom1,
...
9,9,geom9
so after the update, sciana1
contains
1,10,geom10
2,11,geom11
...
CREATE TABLE
statements of both tables so we know datatypes and UNIQUE / PRIMARY KEY constraints.sciana
table have only 1 (or 0) rows?