pltcl
pltcl
pltcl : PL/Tcl procedural language
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3240 | pltcl
|
pltcl
|
1.0 |
LANG
|
PostgreSQL
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-dt-
|
No
|
Yes
|
No
|
Yes
|
no
|
yes
|
| Relationships | |
|---|---|
| Schemas | pg_catalog |
| See Also | plpgsql
plperl
plpython3u
pg_tle
plv8
pllua
pljava
|
| Siblings | pltclu
|
Packages
| PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|
1.0
|
1.0
|
1.0
|
1.0
|
1.0
|
This is a built-in contrib extension ship with the PostgreSQL kernel
Install
Create this extension with:
CREATE EXTENSION pltcl;Usage
PL/Tcl allows writing PostgreSQL functions in the Tcl programming language. As a trusted language, it restricts access to the filesystem and other system resources.
CREATE EXTENSION pltcl;
-- Simple function returning a greeting
CREATE FUNCTION tcl_hello(name text) RETURNS text
LANGUAGE pltcl AS $$
return "Hello, $1!"
$$;
SELECT tcl_hello('world');
-- Function with conditional logic
CREATE FUNCTION tcl_max(a integer, b integer) RETURNS integer
LANGUAGE pltcl AS $$
if {$1 > $2} {return $1}
return $2
$$;
-- Set-returning function
CREATE FUNCTION tcl_sequence(count integer) RETURNS SETOF integer
LANGUAGE pltcl AS $$
for {set i 1} {$i <= $1} {incr i} {
return_next $i
}
$$;
-- Trigger function
CREATE FUNCTION tcl_audit() RETURNS trigger
LANGUAGE pltcl AS $$
set NEW(modified_at) [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]
return [array get NEW]
$$;Database access from PL/Tcl uses the spi_exec command:
CREATE FUNCTION tcl_count_rows(tbl text) RETURNS integer
LANGUAGE pltcl AS $$
spi_exec "SELECT count(*) AS cnt FROM $1"
return $cnt
$$;Last updated on