0
I need to create a materialized view, and I need to create a unique id within that view:
I have a square table with the geometry of the court (which have unique id). I’m crossing the geometry of this table with the geometry of another table, the zoning table.
My final geometry is the intersection (St_intersection) of the two geometries, as you can see in the code below.
I need a unique id for this new geometry. I need it to be a materialized view because this table will be updated with some frequency.
The unique id of the initial geometry does not suit me, as my final geometry is an intersection, ids may be repeated.
At first, I created a sequence and I’m pulling her nextval. It’s working, but I was wondering if it’s possible to do it another way, preferably, so that my new unique id always starts at 1, rather than starting from the nextval of the sequence (which is finite...!).
CREATE MATERIALIZED VIEW mon_nau.quadra_bairro_zon_cent_reg
AS
SELECT
nextval('sequencia'::regclass) AS sub_id,
quadra.id,
zoneamento.tipo_zoneamento,
ST_Intersection (quadra.geom,zoneamento.geom),
FROM quadra
LEFT JOIN
zoneamento
ON ST_Intersects (quadra.geom,zoneamento.geom)
this new key, should always remain the same ? it would not be possible to concatenate the square id with the initial geometry id, something like this ?
– Rovann Linhalis