Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PRINT NULL and PRINT <empty string> #2199

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -409,11 +409,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 @@ -461,6 +461,7 @@ todatetimeoffset-dep
triggers_with_transaction
typeid-typename
typeid-typename-dep
print_null
unquoted_string
doublequoted_string
alter_authorization_change_db_owner
Expand Down
Loading