Search code examples
postgresql-9.1ddlpostgresql-9.0hstore

How do I make a script that properly introduces hstore in both 9.0 and 9.1?


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?


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>