You can't use ALTER VIEW
to drop or add columns. I quote the manual on ALTER VIEW:
ALTER VIEW
changes various auxiliary properties of a view. (If you want to modify the view's defining query, useCREATE OR REPLACE VIEW
.)
But a simple CREATE OR REPLACE VIEW
won't cut it. Another quote from the manual:
The new query must generate the same columns that were generated by the existing view query
So DROP
and CREATE
the view:
DROP VIEW lineview;
CREATE VIEW lineview AS
SELECT *, row_number() OVER(ORDER BY ???) AS num
FROM (
SELECT 'name' AS name_dispatcher, the_geom
FROM line1
UNION
SELECT 'name' AS name_dispatcher, the_geom
FROM line2
UNION
SELECT 'name' AS name_dispatcher, the_geom
FROM line3
) x
I use a subquery because I assume you want to add row_number()
to all rows. Your question is vague in that respect.
If you just want a unique id in no particular order, use row_number() OVER()
.