Database Reference
In-Depth Information
You can see that during the executing the preceding code, it calculates the sum
of three variables correctly. The result can be seen using the following statement:
warehouse_db=# SELECT tcl_arguments(2,3,4);
tcl_arguments
---------------
9
(1 row)
Accessing the database with PL/Tcl
We will use the spi_exec() function whose return value is the number of rows
a query affects.
Let's execute the function and observe results against the warehouse_tbl table.
The array option enables values to be stored in the associated array indexed by the
column name. You can also use another variant of spi_exec() here, with no array
option and loop variable, for example, [spi_exec "SELECT * FROM warehouse_
tbl"] .
The following is an example using the spi_exec() function in the warehouse_tbl
table:
warehouse_db=# CREATE OR REPLACE FUNCTION getRecords_withtcl()
RETURNS integer AS $$
set res [spi_exec -array tblrows "SELECT * FROM
warehouse_tbl"]
return $res;
$$ LANGUAGE pltcl;
Now, try to execute the query on the warehouse_tbl table as follows:
warehouse_db=# SELECT getRecords_withtcl();
getRecords_withtcl
--------------------
3
(1 row)
 
Search WWH ::




Custom Search