Skip to content

Commit

Permalink
Fix the issue that PIVOT execution not return row affected line (babe…
Browse files Browse the repository at this point in the history
…lfish-for-postgresql#2071)


Previous our implement of PIVOT has a issue that it didn't return the
row affected line as result, this fix has fixed the bug.

Task: BABEL-284
Signed-off-by: Zhibai Song <[email protected]>
  • Loading branch information
forestkeeper authored and Jason Teng committed Dec 21, 2023
1 parent 6b22380 commit 148635e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions contrib/babelfishpg_tsql/src/pl_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -4693,6 +4693,12 @@ exec_stmt_execsql(PLtsql_execstate *estate,
return ret;
}

if (expr->plan && expr->plan->oneshot)
{
SPI_freeplan(expr->plan);
expr->plan = NULL;
}

if (expr->plan == NULL)
{
/*
Expand Down Expand Up @@ -5056,11 +5062,10 @@ exec_stmt_execsql(PLtsql_execstate *estate,
/* If query affects IDENTITY_INSERT relation then update sequence */
pltsql_update_identity_insert_sequence(expr);

/* If current plan constains a pivot operator, we remove the plan */
/* If current plan constains a pivot operator, we set it as execute oneshot */
if (is_pivot)
{
SPI_freeplan(expr->plan);
expr->plan = NULL;
expr->plan->oneshot = true;
}

/* Expect SPI_tuptable to be NULL else complain */
Expand Down
2 changes: 2 additions & 0 deletions test/JDBC/expected/pivot-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ PIVOT (
) AS pvt;
SELECT TOP 10 * FROM pivot_insert_into ORDER by 1, 2;
GO
~~ROW COUNT: 197~~

~~START~~
int#!#int#!#int#!#int#!#int#!#int#!#int
1200#!#200#!#0#!#0#!#0#!#0#!#0
Expand Down

0 comments on commit 148635e

Please sign in to comment.