From 40a072175d571cd449832dda52667ecbbb424e15 Mon Sep 17 00:00:00 2001 From: Riley Harris Date: Thu, 2 Nov 2023 09:12:39 -0400 Subject: [PATCH] Explicitly cast postgres function return values Two database functions fail in some versions of postgres, because their output is not explicitly cast to match the expected function return value type. This change simply does the explicit casting to match. --- splink/postgres/linker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/splink/postgres/linker.py b/splink/postgres/linker.py index b8f0c94d90..3ec588174b 100644 --- a/splink/postgres/linker.py +++ b/splink/postgres/linker.py @@ -263,7 +263,7 @@ def _create_months_between_function(self): sql = f""" CREATE OR REPLACE FUNCTION ave_months_between(x date, y date) RETURNS float8 AS $$ - SELECT datediff(x, y)/{ave_length_month}; + SELECT (datediff(x, y)/{ave_length_month})::float8; $$ LANGUAGE SQL IMMUTABLE; """ self._run_sql_execution(sql) @@ -273,7 +273,7 @@ def _create_months_between_function(self): x {dateish_type}, y {dateish_type} ) RETURNS integer AS $$ - SELECT ave_months_between(DATE(x), DATE(y)); + SELECT (ave_months_between(DATE(x), DATE(y)))::int; $$ LANGUAGE SQL IMMUTABLE; """ for dateish_type in ("timestamp", "timestamp with time zone"):