Skip to content

Commit

Permalink
Date functions returns time of transaction instead of time of query (#…
Browse files Browse the repository at this point in the history
…1693)

Get Current Date/time type functions inside a batch were returning the same datetime. This was because we were calling SetCurrentStatementStartTimestamp only at batch level. To fix this, we now call SetCurrentStatementStartTimestamp at statement level.
Moreover, this commit removes the extra definition for GETUTCDATE which was causing behaviour differences.

Issues Resolved
BABEL-4187

Signed-off-by: Kushaal Shroff [email protected]
  • Loading branch information
KushaalShroff authored Aug 9, 2023
1 parent 16f9ff4 commit 8e40917
Show file tree
Hide file tree
Showing 4 changed files with 652 additions and 6 deletions.
6 changes: 0 additions & 6 deletions contrib/babelfishpg_tsql/sql/sys_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1676,12 +1676,6 @@ $BODY$
STRICT
LANGUAGE sql IMMUTABLE;

CREATE OR REPLACE FUNCTION sys.GETUTCDATE() RETURNS sys.DATETIME AS
$BODY$
SELECT CAST(CURRENT_TIMESTAMP AT TIME ZONE 'UTC'::pg_catalog.text AS sys.DATETIME);
$BODY$
LANGUAGE SQL STABLE PARALLEL SAFE;

-- These come from the built-in pg_catalog.count in pg_aggregate.dat
CREATE AGGREGATE sys.count(*)
(
Expand Down
3 changes: 3 additions & 0 deletions contrib/babelfishpg_tsql/src/iterative_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,9 @@ exec_stmt_iterative(PLtsql_execstate *estate, ExecCodes *exec_codes, ExecConfig_

reset_exec_error_data(estate);

/* Set the current Statement Start time at satement level and not at batch. */
SetCurrentStatementStartTimestamp();

/*
* Let the protocol plugin know that we are about to execute this
* statement
Expand Down
Loading

0 comments on commit 8e40917

Please sign in to comment.