Opened 12 years ago

Closed 8 years ago

Last modified 5 years ago

#2236 closed enhancement (fixed)

shp2pgsql -d: can it emit "DROP TABLE IF EXISTS"?

Reported by: pclark Owned by: robe
Priority: medium Milestone: PostGIS 2.3.0
Component: utils/loader-dumper Version: 2.0.x
Keywords: shp2pgsql, gsoc Cc:

Description

Can shp2pgsql emit DROP TABLE IF EXISTS instead of just DROP TABLE when the -d flag is passed?

Attachments (1)

shp2pgsql-core.c_IF_EXISTS.patch (828 bytes ) - added by antimirov 8 years ago.
Added "IF EXISTS" to DROP TABLE statements

Download all attachments as: .zip

Change History (14)

comment:1 by robe, 12 years ago

Milestone: PostGIS FuturePostGIS 2.0.4
Owner: changed from mcayland to robe

seems simple enough. I think all versions we support in 2.0 (8.4-9.2) support DROP TABLE IF EXISTS. Prior versions didn't which I suspect is why we didn't have it.

I think this is also something we can do in 2.0.4 instead of waiting for 2.1.0 because it doesn't change the api and is more the expected behavior

comment:2 by robe, 11 years ago

Milestone: PostGIS 2.0.4PostGIS 2.2.0

comment:3 by robe, 11 years ago

Keywords: gsoc added

comment:4 by robe, 9 years ago

Milestone: PostGIS 2.2.0PostGIS 2.3.0

comment:5 by antimirov, 8 years ago

Hi everyone,

So, just to get it right. The only thing to be changed here is to add 'IF EXISTS' into the SQL statement and this ticket can be closed? Why has it taken this long then? Any hidden complications?

I see the code at loader/shp2pgsql-core.c, lines 1302:1313 and the change seems trivial. Is it okay if I attach a patch here or must it be someone else from the official core team?

Last edited 8 years ago by antimirov (previous) (diff)

comment:6 by strk, 8 years ago

Lack of time from core committers, I guess. Consider attaching a patch, so it takes less time. Especially if you include a testcase (see regress/loader).

by antimirov, 8 years ago

Added "IF EXISTS" to DROP TABLE statements

comment:7 by antimirov, 8 years ago

Hi strk,

I could not find how to add a testcase for -d option of the command itself, because it's not just the data that can be imported or exported. But the patch is pretty simple, you can see yourself.

comment:8 by strk, 8 years ago

loader tests can have a -pre and -post script, plus an -opt (somethign like that). So you could specify -d in the -opt file and either create or not a table with -pre (would be two tests, one with the table and one w/out). The data you could reuse existing one.

comment:9 by strk, 8 years ago

Eugene, your "Common Name" in LDAP lacks a surname: http://www.osgeo.org/cgi-bin/ldap_web_search.py?query=antimirov Consider fixing that via https://www.osgeo.org/cgi-bin/auth/ldap_edit_user.py (I went looking it up for attribution on applying the patch)

comment:10 by strk, 8 years ago

Resolution: fixed
Status: newclosed

In 15005:

Use "DROP TABLE IF EXISTS" on shp2pgsql -d

Patch by Eugene Antimirov
Closes #2236

in reply to:  9 comment:11 by antimirov, 8 years ago

Replying to strk:

Eugene, your "Common Name" in LDAP lacks a surname: http://www.osgeo.org/cgi-bin/ldap_web_search.py?query=antimirov Consider fixing that via https://www.osgeo.org/cgi-bin/auth/ldap_edit_user.py (I went looking it up for attribution on applying the patch)

I think I fixed it.

Thanks for accepting the patch.

comment:12 by pclark, 8 years ago

Thank you!

comment:13 by Sandro Santilli <strk@…>, 5 years ago

In 33fb0c9/git:

Use "DROP TABLE IF EXISTS" on shp2pgsql -d

Patch by Eugene Antimirov
Closes #2236

git-svn-id: http://svn.osgeo.org/postgis/trunk@15005 b70326c6-7e19-0410-871a-916f4a2858ee

Note: See TracTickets for help on using tickets.