forked from babelfish-for-postgresql/babelfish_extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: pranav jain <[email protected]>
- Loading branch information
Showing
2 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.5.0--4.6.0.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
-- complain if script is sourced in psql, rather than via ALTER EXTENSION | ||
\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '4.6.0'" to load this file. \quit | ||
|
||
-- add 'sys' to search path for the convenience | ||
SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false); | ||
|
||
-- Drops an object if it does not have any dependent objects. | ||
-- Is a temporary procedure for use by the upgrade script. Will be dropped at the end of the upgrade. | ||
-- Please have this be one of the first statements executed in this upgrade script. | ||
CREATE OR REPLACE PROCEDURE babelfish_drop_deprecated_object(object_type varchar, schema_name varchar, object_name varchar) AS | ||
$$ | ||
DECLARE | ||
error_msg text; | ||
query1 text; | ||
query2 text; | ||
BEGIN | ||
|
||
query1 := pg_catalog.format('alter extension babelfishpg_tsql drop %s %s.%s', object_type, schema_name, object_name); | ||
query2 := pg_catalog.format('drop %s %s.%s', object_type, schema_name, object_name); | ||
|
||
execute query1; | ||
execute query2; | ||
EXCEPTION | ||
when object_not_in_prerequisite_state then --if 'alter extension' statement fails | ||
GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; | ||
raise warning '%', error_msg; | ||
when dependent_objects_still_exist then --if 'drop view' statement fails | ||
GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; | ||
raise warning '%', error_msg; | ||
end | ||
$$ | ||
LANGUAGE plpgsql; | ||
|
||
-- Please add your SQLs here | ||
/* | ||
* Note: These SQL statements may get executed multiple times specially when some features get backpatched. | ||
* So make sure that any SQL statement (DDL/DML) being added here can be executed multiple times without affecting | ||
* final behaviour. | ||
*/ | ||
|
||
DO $$ | ||
DECLARE | ||
exception_message text; | ||
BEGIN | ||
ALTER FUNCTION sys.suser_name() RENAME TO suser_name_deprecated_4_6_0; | ||
|
||
EXCEPTION WHEN OTHERS THEN | ||
GET STACKED DIAGNOSTICS | ||
exception_message = MESSAGE_TEXT; | ||
RAISE WARNING '%', exception_message; | ||
END; | ||
$$; | ||
|
||
CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'suser_name_deprecated_4_6_0'); | ||
|
||
CREATE OR REPLACE FUNCTION sys.suser_name() | ||
RETURNS sys.NVARCHAR(128) | ||
AS 'babelfishpg_tsql', 'suser_name_current_session' | ||
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE; | ||
|
||
-- Drops the temporary procedure used by the upgrade script. | ||
-- Please have this be one of the last statements executed in this upgrade script. | ||
DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar); | ||
|
||
-- After upgrade, always run analyze for all babelfish catalogs. | ||
CALL sys.analyze_babelfish_catalogs(); | ||
|
||
-- Reset search_path to not affect any subsequent scripts | ||
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters