This is an automated email from the ASF dual-hosted git repository.

rafsun42 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/age.git


The following commit(s) were added to refs/heads/master by this push:
     new 90e0d163 Minor fix in `agtype_volatile_wrapper` function (#1172)
90e0d163 is described below

commit 90e0d163ba150cadc66e27b129a11f0757951335
Author: Wendel de Lana <[email protected]>
AuthorDate: Wed Aug 23 17:14:31 2023 -0300

    Minor fix in `agtype_volatile_wrapper` function (#1172)
    
    Fixed duplicated IF-STATEMENT of INT4OID in agtype_volatile_wrapper
    function changing it to INT2OID
---
 regress/expected/agtype.out    | 24 ++++++++++++++++++++++++
 regress/sql/agtype.sql         |  9 +++++++++
 src/backend/utils/adt/agtype.c |  2 +-
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/regress/expected/agtype.out b/regress/expected/agtype.out
index 65cca0e4..cf451b43 100644
--- a/regress/expected/agtype.out
+++ b/regress/expected/agtype.out
@@ -3192,6 +3192,30 @@ SELECT agtype_btree_cmp(
                -1
 (1 row)
 
+--Int2 to Agtype in agtype_volatile_wrapper
+SELECT ag_catalog.agtype_volatile_wrapper(1::int2);
+ agtype_volatile_wrapper 
+-------------------------
+ 1
+(1 row)
+
+SELECT ag_catalog.agtype_volatile_wrapper(32767::int2);
+ agtype_volatile_wrapper 
+-------------------------
+ 32767
+(1 row)
+
+SELECT ag_catalog.agtype_volatile_wrapper(-32767::int2);
+ agtype_volatile_wrapper 
+-------------------------
+ -32767
+(1 row)
+
+-- These should fail
+SELECT ag_catalog.agtype_volatile_wrapper(32768::int2);
+ERROR:  smallint out of range
+SELECT ag_catalog.agtype_volatile_wrapper(-32768::int2);
+ERROR:  smallint out of range
 --
 -- Cleanup
 --
diff --git a/regress/sql/agtype.sql b/regress/sql/agtype.sql
index 3fb81d01..0e53df2c 100644
--- a/regress/sql/agtype.sql
+++ b/regress/sql/agtype.sql
@@ -925,6 +925,15 @@ SELECT agtype_btree_cmp(
        '[{"id":1, "label":"test", "properties":{"id":100}}::vertex,
          {"id":2, "start_id":1, "end_id": 3, "label":"elabel", 
"properties":{}}::edge,
          {"id":4, "label":"vlabel", "properties":{}}::vertex]::path'::agtype);
+
+--Int2 to Agtype in agtype_volatile_wrapper
+SELECT ag_catalog.agtype_volatile_wrapper(1::int2);
+SELECT ag_catalog.agtype_volatile_wrapper(32767::int2);
+SELECT ag_catalog.agtype_volatile_wrapper(-32767::int2);
+
+-- These should fail
+SELECT ag_catalog.agtype_volatile_wrapper(32768::int2);
+SELECT ag_catalog.agtype_volatile_wrapper(-32768::int2);
 --
 -- Cleanup
 --
diff --git a/src/backend/utils/adt/agtype.c b/src/backend/utils/adt/agtype.c
index 70e5f3b9..ea254016 100644
--- a/src/backend/utils/adt/agtype.c
+++ b/src/backend/utils/adt/agtype.c
@@ -10876,7 +10876,7 @@ Datum agtype_volatile_wrapper(PG_FUNCTION_ARGS)
             {
                 agtv_result.val.int_value = (int64) DatumGetInt32(arg);
             }
-            else if (type == INT4OID)
+            else if (type == INT2OID)
             {
                 agtv_result.val.int_value = (int64) DatumGetInt16(arg);
             }

Reply via email to