The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

ravivundavalli (10) [Avatar] Offline
in your presentation
The following error is issued.

ERROR: syntax error at or near "WITH RECURSIVE"

INSERT INTO land(pid, land_type, land_name, the_geom)
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"

regina.leo (265) [Avatar] Offline
Re: Error in exercise

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)
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 ) ))
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)
WHERE ST_IsValid(the_geom)
GROUP BY pkey;