[postgis-users] problem with apostrophe

Andreas Neumann neumann at karto.baug.ethz.ch
Mon Jan 15 06:29:47 PST 2007


Hello list,

I need to import ESRI shapefiles with french names into Postgis and am 
running into troubles with apostrophs.

Here is one example SQL which generates problems:

INSERT INTO "hydrography" 
("fnode_","tnode_","lpoly_","rpoly_","length","gewaessern","gewaesse_1","buwal_bww","abschnitt","code200","name","name2","km_start","km_ende","typ","k500","k1000","upnormal","upneu","upparallel","upseeneu","downnormal","downparall","klasse","breite",the_geom) 
VALUES 
('2098','2217','0','0','5.11747e+003','6224','6241','1407','1','1407001','L\'Orvine',NULL,'0','5117','0','1','0','0','0','0','0','274001','0','9','9','SRID=21781;0105000000010000000102000000180000000000004049E2214100000000CC5B0B41000000A0D7DF214100000040AB580B41000000A05ADE2141000000607A570B410000000043DD2141000000A04D540B410000000012DC2141000000608E4D0B41000000C0C9D92141000000A065480B41000000C04CD82141000000C034470B410000004068D721410000006096490B41000000009DD6214100000000FC490B4100000000A1D42141000000C034470B4100000040F1D22141000000C040410B41000000C0A8D0214100000060B23B0B410000000078CF2141000000A0813A0B4100000040CACC214100000060B6390B41000000A018CC2141000000C0803A0B41000000C068CA214100000060B6390B410000004084C92141000000401F380B41000000A09FC8214100000060F2340B41000000A0EDC72141000000A095300B41000000A0BCC6214100000040372C0B41000000C0D7C52141000000C074270B4100000000A9C32141000000C080210B41000000A0ACC12141000000402B190B4100000000C8C02141000000402F170B41 
);

Note the trouble with 'L\'Orvine'

When I run "psql -f data.sql -d mydb" I get the following error message:

=========

psql:hydrography.sql:6302: WARNING:  nonstandard use of \' in a string literal

LINE 1: ...'5.11747e+003','6224','6241','1407','1','1407001','L\'Orvine...

                                                             ^

HINT:  Use '' to write quotes in strings, or use the escape string syntax (E'...').

=========

How do I correctly format such a string containing apostrophes? Is there 
an option for shp2pgsql to correctly handle the apostrophs in text 
strings when converting from ESRI shapefiles? Or do I need to choose a 
certain encoding (-W)?

Thanks for any pointer in the right direction. I know there are french 
users on this list, so I am hoping to get answers to my problem.

Andreas

-- 
----------------------------------------------
Andreas Neumann
Institute of Cartography
ETH Zurich
Wolfgang-Paulistrasse 15
CH-8093  Zurich, Switzerland

Phone: ++41-44-633 3031, Fax: ++41-44-633 1153
e-mail: neumann at karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/





More information about the postgis-users mailing list