Skip to content

Commit

Permalink
Support PRINT NULL and PRINT <empty string> (babelfish-for-postgresql…
Browse files Browse the repository at this point in the history
…#2199)

This PR introduces support for printing NULL and <empty string>. When the argument to PRINT is NULL or an empty string, a single space should be printed. However Babelfish currently prints <NULL> and an empty string, respectively.

Signed-off-by: Rob Verschoor [email protected]
  • Loading branch information
robverschoor authored and ritanwar committed Jan 8, 2024
1 parent 0a7bbc6 commit 6662e0a
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 1 deletion.
13 changes: 12 additions & 1 deletion contrib/babelfishpg_tsql/src/pl_exec-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,22 @@ exec_stmt_print(PLtsql_execstate *estate, PLtsql_stmt_print *stmt)
&formattypmod);

if (formatisnull)
extval = "<NULL>";
{
// Printing NULL prints a single space in T-SQL
extval = " ";
}
else
{
extval = convert_value_to_string(estate,
formatdatum,
formattypeid);
}

if (strlen(extval) == 0)
{
// Printing an empty string prints a single space in T-SQL
extval = " ";
}

ereport(INFO, errmsg_internal("%s", extval));

Expand Down
2 changes: 2 additions & 0 deletions test/JDBC/expected/print_null-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
drop procedure p1_print_null
go
10 changes: 10 additions & 0 deletions test/JDBC/expected/print_null-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
create procedure p1_print_null as
declare @v varchar = null
print null
print @v
print ''
set @v = ''
print @v
print ' '
print ' '
go
31 changes: 31 additions & 0 deletions test/JDBC/expected/print_null-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

-- Since the JDBC tests do not capture output from PRINT statements, these tests actually don't do anything
-- Keeping them for when then moment comes that PRINT tests are supported
-- prints a single space:
print null
go

-- prints a single space:
declare @v varchar = null
print @v
go
-- prints a single space:
print ''
go

-- prints a single space:
declare @v varchar = ''
print @v
go

-- prints a single space:
print ' '
go

-- prints two spaces:
print ' '
go

-- same set of tests as above, but inside a stored proc:
exec p1_print_null
go
2 changes: 2 additions & 0 deletions test/JDBC/input/print_null-vu-cleanup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
drop procedure p1_print_null
go
10 changes: 10 additions & 0 deletions test/JDBC/input/print_null-vu-prepare.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
create procedure p1_print_null as
declare @v varchar = null
print null
print @v
print ''
set @v = ''
print @v
print ' '
print ' '
go
31 changes: 31 additions & 0 deletions test/JDBC/input/print_null-vu-verify.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Since the JDBC tests do not capture output from PRINT statements, these tests actually don't do anything
-- Keeping them for when then moment comes that PRINT tests are supported

-- prints a single space:
print null
go

-- prints a single space:
declare @v varchar = null
print @v
go
-- prints a single space:
print ''
go

-- prints a single space:
declare @v varchar = ''
print @v
go

-- prints a single space:
print ' '
go

-- prints two spaces:
print ' '
go

-- same set of tests as above, but inside a stored proc:
exec p1_print_null
go
1 change: 1 addition & 0 deletions test/JDBC/upgrade/latest/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ todatetimeoffset-dep
triggers_with_transaction
typeid-typename
typeid-typename-dep
print_null
unquoted_string
doublequoted_string
alter_authorization_change_db_owner
Expand Down

0 comments on commit 6662e0a

Please sign in to comment.