From 2feeec234cf25e9184887495a671dfe5a70f39d0 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Mon, 12 Jan 2015 09:50:15 +0200 Subject: [PATCH] Fix analyze function for PostgreSQL 9.4 --- CHANGES.rst | 6 ++++++ sqlalchemy_utils/functions/database.py | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0d61a5d..c807a20 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,12 @@ Changelog Here you can see the full list of changes between each SQLAlchemy-Utils release. +0.29.3 (2015-xx-xx) +^^^^^^^^^^^^^^^^^^^ + +- Fixed analyze function runtime property handling for PostgreSQL >= 9.4 + + 0.29.2 (2015-01-08) ^^^^^^^^^^^^^^^^^^^ diff --git a/sqlalchemy_utils/functions/database.py b/sqlalchemy_utils/functions/database.py index 225360f..8642290 100644 --- a/sqlalchemy_utils/functions/database.py +++ b/sqlalchemy_utils/functions/database.py @@ -26,7 +26,15 @@ class PlanAnalysis(object): class QueryAnalysis(object): def __init__(self, result_set): self.plan = result_set[0]['Plan'] - self.runtime = result_set[0]['Total Runtime'] + if 'Total Runtime' in result_set[0]: + # PostgreSQL versions < 9.4 + self.runtime = result_set[0]['Total Runtime'] + else: + # PostgreSQL versions >= 9.4 + self.runtime = ( + result_set[0]['Execution Time'] + + result_set[0]['Planning Time'] + ) @property def node_types(self):