ravivundavalli (10) [Avatar] Offline
#1
Hi,
in your presentation
110_pgcon_spatialanal_postgis.pdf
The following error is issued.

ERROR: syntax error at or near "WITH RECURSIVE"

INSERT INTO land(pid, land_type, land_name, the_geom)
WITH RECURSIVE
p(pkey, atype, the_geom) AS.......

Using Pgsql 8,4 with PostGIS
"POSTGIS="1.3.6" GEOS="3.1.0-CAPI-1.5.0" PROJ="Rel. 4.6.1, 21 August 2008"

Ravi
regina.leo (265) [Avatar] Offline
#2
Re: Error in exercise
Ravi,

Are you sure you are using PostgreSQL 8.4. Its hard to tell with your below.

You need to do a

SELECT version();

To actually see the version of PostgreSQL you are running. The example in the slide wouldn't work for PostgreSQL 8.3 since CTE is an 8.4 feature.

However I noticed that if you cut and paste the example from the PDF, it doesn't work and that's because the line breaks when cutting an pasting mess up the query.

So the CTE expression should really look like this.

INSERT INTO land(pid, land_type, land_name, the_geom)
WITH RECURSIVE
p(pkey, atype, the_geom) AS
(
VALUES (1, 'historical', ST_Multi(ST_Buffer(ST_Transform(ST_GeomFromText('POLYGON((-70.93052 42.31830,-70.93053 42.31840,-70.93053 42.31841,-70.93054 42.31838,-70.93052 42.31830))',4326), 26986),100,1 ) ))
UNION ALL
SELECT pkey + 1, 'historical', ST_Multi(ST_Translate(the_geom, (ST_XMax(the_geom) -
ST_XMin(the_geom)), (ST_YMax(the_geom) - ST_YMin(the_geom))))
FROM p WHERE pkey < 20 )
,
p2(pkey,atype,the_geom) AS
(SELECT lpad(CAST(p.pkey + CAST(random()*100000 As integer) As text),9, '0') , (ARRAY['1
family', 'condo', '2 family', '3 family','commercial', 'government', 'hospital',
'police station', 'college', 'park', 'elementary school', 'highschool', 'vacant
land'])[CAST(random()*12 As integer) + 1],
ST_Multi(ST_Buffer(ST_Translate(p.the_geom,x*i, 2*pi()*sin(i/y) + (ST_YMax(the_geom) -
ST_YMin(the_geom))) ,0, mod(i,p.pkey) ))
FROM p CROSS JOIN (SELECT MAX(CAST(ST_XMax(the_geom) - ST_XMin(the_geom) As integer)) As
x FROM p ) As x CROSS JOIN (SELECT Max(CAST(ST_YMax(the_geom) - ST_YMin(the_geom) As
integer)) As y FROM p) As y
CROSS JOIN (SELECT CAST(2*n*sin(n*2/360.0) As integer) FROM generate_series(1,250) As n
WHERE sin(n/360.0) <> 0) As i(i)
WHERE mod(i, p.pkey) between 1 and 4
)
SELECT pkey As pid, MIN(atype), MIN(atype) || pkey, MAX(the_geom)
FROM p2
WHERE ST_IsValid(the_geom)
GROUP BY pkey;

Leo