diff --git a/db/postgresql/functions/nvl.sql b/db/postgresql/functions/nvl.sql index 7e069dff00..e7675ac469 100644 --- a/db/postgresql/functions/nvl.sql +++ b/db/postgresql/functions/nvl.sql @@ -28,3 +28,13 @@ BEGIN END; $function$ ; + +CREATE or REPLACE FUNCTION nvl (text, text ) RETURNS text +LANGUAGE plpgsql +IMMUTABLE +AS $function$ +BEGIN + RETURN COALESCE($1, $2); +END; +$function$ +; diff --git a/migration/i9/oracle/202211201304_IDEMPIERE-5484.sql b/migration/i9/oracle/202211201304_IDEMPIERE-5484.sql new file mode 100644 index 0000000000..e696cfdf9f --- /dev/null +++ b/migration/i9/oracle/202211201304_IDEMPIERE-5484.sql @@ -0,0 +1,4 @@ +-- IDEMPIERE-5484 Import GL Journal fails with SQL error because of NVL +-- PostgreSQL only +SELECT register_migration_script('202211201304_IDEMPIERE-5484.sql') FROM dual; + diff --git a/migration/i9/postgresql/202211201304_IDEMPIERE-5484.sql b/migration/i9/postgresql/202211201304_IDEMPIERE-5484.sql new file mode 100644 index 0000000000..adea743ee7 --- /dev/null +++ b/migration/i9/postgresql/202211201304_IDEMPIERE-5484.sql @@ -0,0 +1,13 @@ +-- IDEMPIERE-5484 Import GL Journal fails with SQL error because of NVL +SELECT register_migration_script('202211201304_IDEMPIERE-5484.sql') FROM dual; + +CREATE or REPLACE FUNCTION nvl (text, text ) RETURNS text +LANGUAGE plpgsql +IMMUTABLE +AS $function$ +BEGIN + RETURN COALESCE($1, $2); +END; +$function$ +; + diff --git a/org.idempiere.test/src/org/idempiere/test/base/DBTest.java b/org.idempiere.test/src/org/idempiere/test/base/DBTest.java index 9037e08cb3..9f45d6c1ff 100644 --- a/org.idempiere.test/src/org/idempiere/test/base/DBTest.java +++ b/org.idempiere.test/src/org/idempiere/test/base/DBTest.java @@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.sql.Timestamp; @@ -274,4 +275,20 @@ public class DBTest extends AbstractTestCase } assertEquals(3, match); } + + @Test + public void test_NVL() throws Exception + { + // multi datatype NVL + // numeric, integer + BigDecimal result = DB.getSQLValueBDEx(null, "SELECT NVL(GrandTotal, 0) FROM C_Order WHERE C_Order_ID=100"); + assertTrue(result != null); + // integer, numeric + result = DB.getSQLValueBDEx(null, "SELECT NVL(10, C_Order_ID) FROM C_Order WHERE C_Order_ID=100"); + assertTrue(result != null); + // Varchar, Text + String resultStr = DB.getSQLValueStringEx(null, "SELECT NVL(Description, C_Charge_ID||' ') FROM C_Charge WHERE C_Charge_ID=101"); + assertTrue(resultStr != null); + } + }