create function tcl_int4cmp(int4,int4) returns int4as' if {$1 < $2} { return -1
} if {$1 > $2} { return1
} return0 ' language pltcl;
CREATE OPERATOR CLASS tcl_int4_ops FOR TYPE int4USING btree AS
OPERATOR 1 @<,
OPERATOR 2 @<=,
OPERATOR 3 @=,
OPERATOR 4 @>=,
OPERATOR 5 @>,
FUNCTION 1 tcl_int4cmp(int4,int4) ;
-- -- Test usage of Tcl's "clock" command. In recent Tcl versions this -- command fails without working "unknown" support, so it's a good canary -- for initialization problems. -- create function tcl_date_week(int4,int4,int4) returns text as $$ return [clock format [clock scan "$2/$3/$1" -gmt 1] -format "%U" -gmt 1]
$$ language pltcl immutable;
-- test pltcl event triggers create function tclsnitch() returns event_trigger language pltcl as $$
elog NOTICE "tclsnitch: $TG_event $TG_tag"
$$;
create event trigger tcl_a_snitch on ddl_command_start execute procedure tclsnitch(); create event trigger tcl_b_snitch on ddl_command_end execute procedure tclsnitch();
create function foobar() returns int language sqlas $$select1;$$; alter function foobar() cost 77; drop function foobar();
createtable foo(); droptable foo;
drop event trigger tcl_a_snitch; drop event trigger tcl_b_snitch;
create function tcl_test_cube_squared(inint, out squared int, out cubed int) as $$ return [list squared [expr {$1 * $1}] cubed [expr {$1 * $1 * $1}]]
$$ language pltcl;
create function tcl_test_squared_rows(int,int) returns table (x int, y int) as $$ for {set i $1} {$i < $2} {incr i} {
return_next [list y [expr {$i * $i}] x $i]
}
$$ language pltcl;
create function tcl_test_sequence(int,int) returns setof intas $$ for {set i $1} {$i < $2} {incr i} {
return_next $i
}
$$ language pltcl;
create function tcl_eval(string text) returns text as $$
eval $1
$$ language pltcl;
-- test use of errorCode in error handling create function tcl_error_handling_test(text) returns text
language pltcl as $function$ if {[catch $1 err]} {
# Ifnot a Postgres error, just return the basic error message if {[lindex $::errorCode 0] != "POSTGRES"} { return $err
}
# Get rid of keys that can't be expected to remain constant
array set myArray $::errorCode
unset myArray(POSTGRES)
unset -nocomplain myArray(funcname)
unset -nocomplain myArray(filename)
unset -nocomplain myArray(lineno)
# Format into something nicer set vals []
foreach {key} [lsort [array names myArray]] { set value [string map {"\n""\n\t"} $myArray($key)]
lappend vals "$key: $value"
} return [join $vals "\n"]
} else { return"no error"
}
$function$;
-- test spi_exec and spi_execp with -array create function tcl_spi_exec(
prepare boolean,
action text
)
returns void language pltcl AS $function$ set query "select * from (values (1,'foo'),(2,'bar'),(3,'baz')) v(col1,col2)" if {$1 == "t"} { set prep [spi_prepare $query {}]
spi_execp -array A $prep {
elog NOTICE "col1 $A(col1), col2 $A(col2)"
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.19Bemerkung:
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.