http://www.perlmonks.org?node_id=1226235


in reply to GeoIP revisited

Just a thought: you could insert a 'IF NOT EXISTS'-create just before the TRUNCATE-statement so that the program 'Just Works' if the table isn't there.

$dbh->do(" CREATE TABLE IF NOT EXISTS geoip ( netblock cidr NOT NULL, country_code text NOT NULL, country_name text NOT NULL, CONSTRAINT geoip_pk PRIMARY KEY (netblock) );" ) or die($dbh->errstr);

IF NOT EXISTS was added to CREATE TABLE long ago and all supported versions of postgres support it.

(I removed the oids- and tablespace-stuff, as I didn't need that.)

Replies are listed 'Best First'.
Re^2: GeoIP revisited
by cavac (Parson) on Nov 27, 2018 at 14:04 UTC

    Good catch. A lot of other tables in my database already have triggers that access the geoip table (productive system with a slight dose of feature creep), so i never thought of adding the table creation into this script...

    perl -e 'use MIME::Base64; print decode_base64("4pmsIE5ldmVyIGdvbm5hIGdpdmUgeW91IHVwCiAgTmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duLi4uIOKZqwo=");'