maintaining backwards compatibility for to_regclass argument type change from cstring to text

From: Michael Rasmussen <michaelr(at)porch(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: maintaining backwards compatibility for to_regclass argument type change from cstring to text
Date: 2016-11-30 23:14:19
Message-ID: 1854E18E-D00D-4DF7-9955-993AA3320043@porch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have encountered an issue in testing our upgrade from 9.4.4 to 9.6.1. Per the changes detailed in https://www.postgresql.org/message-id/E1aGVwY-0002Pu-Uk%40gemulon.postgresql.org, the argument types of the to_reg*() functions were changed from cstring to text.

We have some plpgsql helper functions for our developers that run some dynamic SQL. At the time, we had followed the solution of doing a hard cast to cstring as found on Stack Overflow at http://stackoverflow.com/questions/31648730/postgres-convert-text-to-string-or-difference-between-abc-vs-a-bc and http://stackoverflow.com/questions/33952892/use-dynamically-created-name-in-to-regclass-function, because there are no implicit conversions between cstring to text nor text to cstring.

I am now faced with having to support both 9.4 and 9.6 as we will not be upgrading all servers simultaneously. The solution I have come up with is to use if-else statements that check the numeric version of the cluster the function is installed on. An example:

if current_setting('server_version_num')::integer < 90600 then
raise notice '%', to_regclass((myschema||'. '||mytable)::cstring);
else
raise notice '%', to_regclass(myschema||'. '||mytable);
end if;

I wanted to confirm, is this the best way to approach this?

--
Michael Rasmussen
Sr. Data Engineer
Porch

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2016-12-01 00:04:36 Re: Logging for 2 instances of PostgreSQL
Previous Message George Weaver 2016-11-30 23:01:14 Logging for 2 instances of PostgreSQL