Question

I am trying to introduce the hstore type into the database of a project I'm developing. But the problem is that I have a slightly newer version of the Postgres server installed on my development machine than there is on the production machine. While I can simply execute the CREATE EXTENSION command locally, this command is unavailable on the production machine.

Is there a way to create a script that will install hstore both on 9.1 and 9.0?

Was it helpful?

Solution

For 9.0, you could use a script like this (ex: create_hstore.sh):

#!/bin/bash

DB=$1
ARGS="-U postgres -h localhost"
CONTRIB=/usr/pgsql-9.0/share/contrib

[ $# -lt 1 ] && exit 1

# Uncomment following lines if necessary
#createdb $ARGS $DB
#createlang $ARGS plpgsql $DB
psql $ARGS -f $CONTRIB/hstore.sql $DB

and then to invoke it:

./create_hstore.sh <db_name>

OTHER TIPS

... if there was a way to determine which PG version is currently installed in the system.

Ask Postgres:

psql -c 'select version()' postgres

Or, if you are confident that the version of psql is in sync:

psql --version
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top