aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pl/tcl/expected/pltcl_queries.out47
-rw-r--r--src/pl/tcl/expected/pltcl_queries_1.out47
-rw-r--r--src/pl/tcl/expected/pltcl_setup.out13
-rw-r--r--src/pl/tcl/sql/pltcl_queries.sql15
-rw-r--r--src/pl/tcl/sql/pltcl_setup.sql18
5 files changed, 140 insertions, 0 deletions
diff --git a/src/pl/tcl/expected/pltcl_queries.out b/src/pl/tcl/expected/pltcl_queries.out
index b585736f711..ba250a218b2 100644
--- a/src/pl/tcl/expected/pltcl_queries.out
+++ b/src/pl/tcl/expected/pltcl_queries.out
@@ -256,3 +256,50 @@ NOTICE: TG_table_name: trigger_test
NOTICE: TG_table_schema: public
NOTICE: TG_when: BEFORE
NOTICE: args: {23 skidoo}
+-- Test composite-type arguments
+select tcl_composite_arg_ref1(row('tkey', 42, 'ref2'));
+ tcl_composite_arg_ref1
+------------------------
+ 42
+(1 row)
+
+select tcl_composite_arg_ref2(row('tkey', 42, 'ref2'));
+ tcl_composite_arg_ref2
+------------------------
+ ref2
+(1 row)
+
+-- Test argisnull primitive
+select tcl_argisnull('foo');
+ tcl_argisnull
+---------------
+ f
+(1 row)
+
+select tcl_argisnull('');
+ tcl_argisnull
+---------------
+ f
+(1 row)
+
+select tcl_argisnull(null);
+ tcl_argisnull
+---------------
+ t
+(1 row)
+
+-- Test spi_lastoid primitive
+create temp table t1 (f1 int);
+select tcl_lastoid('t1');
+ tcl_lastoid
+-------------
+ 0
+(1 row)
+
+create temp table t2 (f1 int) with oids;
+select tcl_lastoid('t2') > 0;
+ ?column?
+----------
+ t
+(1 row)
+
diff --git a/src/pl/tcl/expected/pltcl_queries_1.out b/src/pl/tcl/expected/pltcl_queries_1.out
index e3fd24d6b10..20efdb4104c 100644
--- a/src/pl/tcl/expected/pltcl_queries_1.out
+++ b/src/pl/tcl/expected/pltcl_queries_1.out
@@ -256,3 +256,50 @@ NOTICE: TG_table_name: trigger_test
NOTICE: TG_table_schema: public
NOTICE: TG_when: BEFORE
NOTICE: args: {23 skidoo}
+-- Test composite-type arguments
+select tcl_composite_arg_ref1(row('tkey', 42, 'ref2'));
+ tcl_composite_arg_ref1
+------------------------
+ 42
+(1 row)
+
+select tcl_composite_arg_ref2(row('tkey', 42, 'ref2'));
+ tcl_composite_arg_ref2
+------------------------
+ ref2
+(1 row)
+
+-- Test argisnull primitive
+select tcl_argisnull('foo');
+ tcl_argisnull
+---------------
+ f
+(1 row)
+
+select tcl_argisnull('');
+ tcl_argisnull
+---------------
+ f
+(1 row)
+
+select tcl_argisnull(null);
+ tcl_argisnull
+---------------
+ t
+(1 row)
+
+-- Test spi_lastoid primitive
+create temp table t1 (f1 int);
+select tcl_lastoid('t1');
+ tcl_lastoid
+-------------
+ 0
+(1 row)
+
+create temp table t2 (f1 int) with oids;
+select tcl_lastoid('t2') > 0;
+ ?column?
+----------
+ t
+(1 row)
+
diff --git a/src/pl/tcl/expected/pltcl_setup.out b/src/pl/tcl/expected/pltcl_setup.out
index 4183c14b28a..e11718c64b3 100644
--- a/src/pl/tcl/expected/pltcl_setup.out
+++ b/src/pl/tcl/expected/pltcl_setup.out
@@ -398,6 +398,19 @@ create trigger dta1_before before insert or update on T_dta1
create trigger dta2_before before insert or update on T_dta2
for each row execute procedure
check_primkey('ref1', 'ref2', 'T_pkey2', 'key1', 'key2');
+create function tcl_composite_arg_ref1(T_dta1) returns int as '
+ return $1(ref1)
+' language pltcl;
+create function tcl_composite_arg_ref2(T_dta1) returns text as '
+ return $1(ref2)
+' language pltcl;
+create function tcl_argisnull(text) returns bool as '
+ argisnull 1
+' language pltcl;
+create function tcl_lastoid(tabname text) returns int8 as '
+ spi_exec "insert into $1 default values"
+ spi_lastoid
+' language pltcl;
create function tcl_int4add(int4,int4) returns int4 as '
return [expr $1 + $2]
' language pltcl;
diff --git a/src/pl/tcl/sql/pltcl_queries.sql b/src/pl/tcl/sql/pltcl_queries.sql
index ee711d5170a..205bc4266ae 100644
--- a/src/pl/tcl/sql/pltcl_queries.sql
+++ b/src/pl/tcl/sql/pltcl_queries.sql
@@ -82,3 +82,18 @@ delete from trigger_test_view;
update trigger_test set v = 'update' where i = 1;
delete from trigger_test;
+
+-- Test composite-type arguments
+select tcl_composite_arg_ref1(row('tkey', 42, 'ref2'));
+select tcl_composite_arg_ref2(row('tkey', 42, 'ref2'));
+
+-- Test argisnull primitive
+select tcl_argisnull('foo');
+select tcl_argisnull('');
+select tcl_argisnull(null);
+
+-- Test spi_lastoid primitive
+create temp table t1 (f1 int);
+select tcl_lastoid('t1');
+create temp table t2 (f1 int) with oids;
+select tcl_lastoid('t2') > 0;
diff --git a/src/pl/tcl/sql/pltcl_setup.sql b/src/pl/tcl/sql/pltcl_setup.sql
index 84629963229..53358ea361f 100644
--- a/src/pl/tcl/sql/pltcl_setup.sql
+++ b/src/pl/tcl/sql/pltcl_setup.sql
@@ -429,6 +429,24 @@ create trigger dta2_before before insert or update on T_dta2
check_primkey('ref1', 'ref2', 'T_pkey2', 'key1', 'key2');
+create function tcl_composite_arg_ref1(T_dta1) returns int as '
+ return $1(ref1)
+' language pltcl;
+
+create function tcl_composite_arg_ref2(T_dta1) returns text as '
+ return $1(ref2)
+' language pltcl;
+
+create function tcl_argisnull(text) returns bool as '
+ argisnull 1
+' language pltcl;
+
+create function tcl_lastoid(tabname text) returns int8 as '
+ spi_exec "insert into $1 default values"
+ spi_lastoid
+' language pltcl;
+
+
create function tcl_int4add(int4,int4) returns int4 as '
return [expr $1 + $2]
' language pltcl;