Skip to content

Commit bb181d1

Browse files
fix empty string handling for ASCII SQL function
1 parent 2b53c49 commit bb181d1

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎contrib/ivorysql_ora/expected/ora_ascii.out‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ select ascii(to_char('2026-01-22 01:02:03.00 +01:00'::timestamptz,'DD-MON-YYYY H
5050
50
5151
(1 row)
5252

53+
select ascii('') is null from dual;
54+
?column?
55+
----------
56+
t
57+
(1 row)
58+

‎contrib/ivorysql_ora/sql/ora_ascii.sql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ select ascii(to_char('2026-01-01'::date,'DD-MON-YYYY HH24:MI:SS')) from dual;
1717
select ascii(to_char('2026-01-11 01:02:03.00'::timestamp,'DD-MON-YYYY HH24:MI:SS.FF6')) from dual;
1818

1919
select ascii(to_char('2026-01-22 01:02:03.00 +01:00'::timestamptz,'DD-MON-YYYY HH24:MI:SS TZH:TZM')) from dual;
20+
21+
select ascii('') is null from dual;

‎contrib/ivorysql_ora/src/builtin_functions/character_datatype_functions.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,8 +2431,13 @@ ora_ascii(PG_FUNCTION_ARGS)
24312431
}
24322432
}
24332433

2434-
if (str == NULL || str[0] == '\0')
2435-
PG_RETURN_INT32(0);
2434+
if (str == NULL || str[0] == '\0') {
2435+
/* 1. Set the null flag */
2436+
fcinfo->isnull = true;
2437+
2438+
/* 2. Return a placeholder value */
2439+
PG_RETURN_VOID();
2440+
}
24362441

24372442
PG_RETURN_INT32((unsigned char) str[0]);
24382443
}

0 commit comments

Comments
 (0)