#3701 closed defect (fixed)
Escape double quotes issue in pgsql2shp
Reported by: | kalxas | Owned by: | robe |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 2.3.3 |
Component: | postgis | Version: | 2.2.x |
Keywords: | Cc: |
Description
On behalf of Sergej Dugokontov:
Error executing main scan query: ERROR: zero-length delimited identifier at or near """" LINE 1: DECLARE cur CURSOR FOR SELECT ""quoteColumn",ST_AsEWKB(ST_Se…
If I change sql to:
SELECT c1 AS "geom", c2 AS """""quoteColumn" FROM t1
I got different error:
Error executing main scan query: ERROR: column ""quoteColumn" does not exist LINE 1: DECLARE cur CURSOR FOR SELECT """quoteColumn",ST_AsEWKB(ST_S... ^ HINT: Perhaps you meant to reference the column "__pgsql2shp22020_tmp_table.""quoteColumn".
I use pgsql2shp RELEASE: 2.2.1 (r14555)
on Ubuntu 16.04 LTS and don't
have any issues if column alias in sql doesn't contain double quotes.
Change History (7)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Milestone: | PostGIS PostgreSQL → PostGIS 2.3.3 |
---|
I don't think that DBFs support columns with quotes in them to being with. Why is it you are wanting to do this? Seems strange to want to alias a column to have quotes.
I did this for example and it worked using
RELEASE: 2.3.1dev (r15238)
pgsql2shp -r -g geom -f test pgr "SELECT ST_SetSRID(ST_Point(1,2)::geometry,4326) AS "geom", 1 AS """quoteColumn""
However the output column gets output as QUOTECOLUMN
If you use the -k option to preserve case, the quotes still get stripped I think
pgsql2shp -k -r -g geom -f test pgr "SELECT ST_SetSRID(ST_Point(1,2)::geometry,4326) AS "geom", 1 AS """quoteColumn""
So my dbf column ends up being quoteColumn.
Anyrate, I think your quoting might still be off by a bit and seems like a waste of effort.
comment:3 by , 8 years ago
okay I tried again with this, which might be what you meant.
I started off with a table that has quotes in column:
So my dbf column ends up being quoteColumn. Anyrate, I think your quoting might still be off by a bit and seems like a waste of effort. I also tried this first creating a table: {{{ SELECT ST_SetSRID(ST_Point(1,2)::geometry,4326) AS "geom", 1 AS """quoteColumn" INTO testq; }}} Then outputing the table {{{ --run from psql SELECT ST_SetSRID(ST_Point(1,2)::geometry,4326) AS "geom", 1 AS """quoteColumn" INTO testq;
Then I tried to export the table
pgsql2shp -r -g geom -f testq pgr testq
and it failed with your error.
Initializing... Error executing main scan query: ERROR: zero-length delimited identifier at or near """" LINE 1: DECLARE cur CURSOR FOR SELECT ""quoteColumn",ST_AsEWKB(ST_Se... ^
So seems there is something wrong with our quote escaping logic.
comment:4 by , 7 years ago
Owner: | changed from | to
---|
Reposting:
I have an issue when I try to create shapefile using pgsql2shp if column alias contains double quotes. For example, my SQL query is:
I store this sql in a file, and if I run from console
I get following error:
If I change sql to:
I got different error:
I use
pgsql2shp RELEASE: 2.2.1 (r14555)
on Ubuntu 16.04 LTS and don't have any issues if column alias in sql doesn't contain double quotes.