Skip to content

Commit

Permalink
Merge d210613 into 92f2596
Browse files Browse the repository at this point in the history
  • Loading branch information
Sairakan committed Jun 13, 2024
2 parents 92f2596 + d210613 commit 048b184
Show file tree
Hide file tree
Showing 9 changed files with 1,153 additions and 7 deletions.
20 changes: 16 additions & 4 deletions .github/configuration/upgrade-test-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ upgrade-version: [{
{
upgrade-path: [
{
version: '14.12',
version: '14.13',
upgrade-type: null
},
{
Expand Down Expand Up @@ -146,6 +146,18 @@ upgrade-version: [{
}
]
},
{
upgrade-path: [
{
version: 15.7,
upgrade-type: null
},
{
version: target.latest,
upgrade-type: minor
}
]
},
{
upgrade-path: [
{
Expand Down Expand Up @@ -175,7 +187,7 @@ upgrade-version: [{
{
upgrade-path: [
{
version: '14.12',
version: '14.13',
upgrade-type: null
},
{
Expand All @@ -192,7 +204,7 @@ upgrade-version: [{
upgrade-type: null,
},
{
version: '14.12',
version: '14.13',
upgrade-type: major,
},
{
Expand All @@ -209,7 +221,7 @@ upgrade-version: [{
upgrade-type: null,
},
{
version: '14.12',
version: '14.13',
upgrade-type: minor,
},
{
Expand Down
6 changes: 6 additions & 0 deletions .github/template/version-branch-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
engine_branch: BABEL_2_8_STABLE__PG_14_11
extension_branch: BABEL_2_8_STABLE
'14.12':
engine_branch: BABEL_2_9_STABLE__PG_14_12
extension_branch: BABEL_2_9_STABLE
'14.13':
engine_branch: BABEL_2_X_DEV__PG_14_X
extension_branch: BABEL_2_X_DEV
'15.2':
Expand All @@ -58,6 +61,9 @@
'15.6':
engine_branch: BABEL_3_5_STABLE__PG_15_6
extension_branch: BABEL_3_5_STABLE
'15.7':
engine_branch: BABEL_3_6_STABLE__PG_15_7
extension_branch: BABEL_3_6_STABLE
'source.latest':
engine_branch: latest
extension_branch: latest
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/Version.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# places during the build process

PGTSQL_MAJOR_VERSION=3
PGTSQL_MINOR_VERSION=6
PGTSQL_MINOR_VERSION=7
PGTSQL_MICRO_VERSION=0

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '3.0.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);

-- please add your SQL here

CREATE OR REPLACE FUNCTION sys.babelfish_update_server_collation_name() RETURNS VOID
LANGUAGE C
AS 'babelfishpg_common', 'babelfish_update_server_collation_name';

SELECT sys.babelfish_update_server_collation_name();

DROP FUNCTION sys.babelfish_update_server_collation_name();

-- reset babelfishpg_tsql.restored_server_collation_name GUC
do
language plpgsql
$$
declare
query text;
begin
query := pg_catalog.format('alter database %s reset babelfishpg_tsql.restored_server_collation_name', CURRENT_DATABASE());
execute query;
end;
$$;

CREATE OR REPLACE FUNCTION sys.datepart_internal(IN datepart PG_CATALOG.TEXT, IN arg anyelement,IN df_tz INTEGER DEFAULT 0) RETURNS INTEGER AS $$
DECLARE
result INTEGER;
first_day DATE;
first_week_end INTEGER;
day INTEGER;
BEGIN
CASE datepart
WHEN 'dow' THEN
result = (date_part(datepart, arg)::INTEGER - current_setting('babelfishpg_tsql.datefirst')::INTEGER + 7) % 7 + 1;
WHEN 'tsql_week' THEN
first_day = make_date(date_part('year', arg)::INTEGER, 1, 1);
first_week_end = 8 - sys.datepart_internal('dow', first_day)::INTEGER;
day = date_part('doy', arg)::INTEGER;
IF day <= first_week_end THEN
result = 1;
ELSE
result = 2 + (day - first_week_end - 1) / 7;
END IF;
WHEN 'second' THEN
result = TRUNC(date_part(datepart, arg))::INTEGER;
WHEN 'millisecond' THEN
result = right(date_part(datepart, arg)::TEXT, 3)::INTEGER;
WHEN 'microsecond' THEN
result = right(date_part(datepart, arg)::TEXT, 6)::INTEGER;
WHEN 'nanosecond' THEN
-- Best we can do - Postgres does not support nanosecond precision
result = right(date_part('microsecond', arg)::TEXT, 6)::INTEGER * 1000;
WHEN 'tzoffset' THEN
-- timezone for datetimeoffset
result = df_tz;
ELSE
result = date_part(datepart, arg)::INTEGER;
END CASE;
RETURN result;
EXCEPTION WHEN invalid_parameter_value or feature_not_supported THEN
-- date_part() throws an exception when trying to get day/month/year etc. from
-- TIME, so we just need to catch the exception in this case
-- date_part() returns 0 when trying to get hour/minute/second etc. from
-- DATE, which is the desirable behavior for datepart() as well.
-- If the date argument data type does not have the specified datepart,
-- date_part() will return the default value for that datepart.
CASE datepart
-- Case for datepart is year, yy and yyyy, all mappings are defined in gram.y.
WHEN 'year' THEN RETURN 1900;
-- Case for datepart is quater, qq and q
WHEN 'quarter' THEN RETURN 1;
-- Case for datepart is month, mm and m
WHEN 'month' THEN RETURN 1;
-- Case for datepart is day, dd and d
WHEN 'day' THEN RETURN 1;
-- Case for datepart is dayofyear, dy
WHEN 'doy' THEN RETURN 1;
-- Case for datepart is y(also refers to dayofyear)
WHEN 'y' THEN RETURN 1;
-- Case for datepart is week, wk and ww
WHEN 'tsql_week' THEN RETURN 1;
-- Case for datepart is iso_week, isowk and isoww
WHEN 'week' THEN RETURN 1;
-- Case for datepart is tzoffset and tz
WHEN 'tzoffset' THEN RETURN 0;
-- Case for datepart is weekday and dw, return dow according to datefirst
WHEN 'dow' THEN
RETURN (1 - current_setting('babelfishpg_tsql.datefirst')::INTEGER + 7) % 7 + 1 ;
ELSE
RAISE EXCEPTION '''%'' is not a recognized datepart option', datepart;
RETURN -1;
END CASE;
END;
$$
STRICT
LANGUAGE plpgsql IMMUTABLE;

-- Reset search_path to not affect any subsequent scripts
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false);
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '3.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.
*/

-- 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);
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/src/babelfish_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*-------------------------------------------------------------------------
*/

#define BABELFISH_VERSION_STR "3.6.0"
#define BABELFISH_INTERNAL_VERSION_STR "Babelfish 15.7.0.0"
#define BABELFISH_VERSION_STR "3.7.0"
#define BABELFISH_INTERNAL_VERSION_STR "Babelfish 15.8.0.0"
#define BABEL_COMPATIBILITY_VERSION "12.0.2000.8"
#define BABEL_COMPATIBILITY_MAJOR_VERSION "12"
Loading

0 comments on commit 048b184

Please sign in to comment.