try:
    from psycopg2cffi import compat
except ImportError:
    pass
else:
    compat.register()


import os
import psycopg2
import psycopg2.extras


class PostgreSQLPersistance(object):
    protocol = 'postgres'

    def __init__(self, details, autocommit=False):
        connection = psycopg2.connect(details)
        connection.autocommit = autocommit
        cursor = connection.cursor(cursor_factory=psycopg2.extras.DictCursor)

        self._connection = connection
        self._cursor = cursor

    def __iter__(self):
        for iter in self._cursor:
            yield iter

    def commit(self):
        return self._connection.commit()

    def rollback(self):
        return self._connection.rollback()

    def execute(self, *args, **kwargs):
        return self._cursor.execute(*args, **kwargs)

    def executemany(self, *args, **kwargs):
        return self._cursor.executemany(*args, **kwargs)

    def fetchone(self):
        return self._cursor.fetchone()

    def set_autocommit(self, autocommit):
        self._connection.autocommit = autocommit

    def get_last_row_id(self):
        self._cursor.execute("SELECT LASTVAL();")
        return self._cursor.fetchone()['lastval']

    def install(self):
        self.create_schema()
        self.create_triggers()

    def create_schema(self):
        script_folder = os.path.split(os.path.realpath(__file__))[0]
        path = os.path.join(script_folder, '..', 'sql', 'schema.sql')
        self._cursor.execute(open(path).read())

    def create_triggers(self):
        script_folder = os.path.split(os.path.realpath(__file__))[0]
        path = os.path.join(script_folder, '..', 'sql', 'triggers.sql')
        self._cursor.execute(open(path).read())

    def drop_tables(self):
        self._cursor.execute("DROP TABLE IF EXISTS nodes;")
        self._cursor.execute("DROP TABLE IF EXISTS ancestors;")

    def flush_tables(self):
        self._cursor.execute("TRUNCATE TABLE nodes RESTART IDENTITY;")
        self._cursor.execute("TRUNCATE TABLE ancestors;")

@@ -143,16 +143,55 @@
 extras%0A%0A
+REQUIRED_POSTGRES_VERSION = (9, 4, 0)%0A%0A
 %0Aclass P
@@ -536,16 +536,79 @@
 cursor%0A%0A
+        self.check_postgres_version()%0A        self.rollback()%0A%0A
     def 
@@ -1242,24 +1242,24 @@
 ASTVAL();%22)%0A
-
         retu
@@ -1297,16 +1297,531 @@
 tval'%5D%0A%0A
+    def check_postgres_version(self):%0A        self._cursor.execute(%22SHOW server_version;%22)%0A        result = self._cursor.fetchone()%5B'server_version'%5D%0A        server_version = tuple(map(int, result.split('.')))%0A        if server_version %3C REQUIRED_POSTGRES_VERSION:%0A            msg = 'Insufficient Postgres version: %7B%7D, required: %7B%7D'%0A            msg = msg.format('.'.join(map(str, server_version)),%0A                             '.'.join(map(str, REQUIRED_POSTGRES_VERSION)))%0A            raise EnvironmentError(msg)%0A%0A
     def 

check for postgres server version