Обсуждение: clock command regression in pltcl?
I have the following function defined: create function _date_week(int4,int4,int4) returns text language pltcl immutable as $$ return [clock format [clock scan "$2/$3/$1"] -format "%U"] $$; It worked fine in 8.3 but in 8.4 now I try to build an index using the function and get: SQL ERROR: In database query: begin; create index i_pay_req_empl_id_week on pay_req (empl_id,(date_week(wdate)));: ERROR: invalid command name "clock" CONTEXT: invalid command name "clock" invoked from within "clock scan "$2/$3/$1"" (procedure "__PLTcl_proc_12360682" line 3) invoked from within "__PLTcl_proc_12360682 2003 12 20" in PL/Tcl function "_date_week" PL/pgSQL function "date_week" line 13 at assignment Is this a regression or is there a reason the clock command is no longer accessible? Kyle
Kyle Bateman <kyle@actarg.com> writes: > I have the following function defined: > create function _date_week(int4,int4,int4) returns text language pltcl > immutable as $$ > return [clock format [clock scan "$2/$3/$1"] -format "%U"] > $$; > It worked fine in 8.3 but in 8.4 now I try to build an index using the > function and get: > (empl_id,(date_week(wdate)));: ERROR: invalid command name "clock" Are you using the same underlying version of tcl as before? What I'm seeing is that tcl seems to have dropped "clock" from the set of commands considered "safe" between tcl 8.4 and 8.5 --- with 8.5 you can only get at it in pltclu. The version of PG isn't relevant. I am not sure if this is a bug or an intentional change on their part. Apparently "clock" was completely rewritten in 8.5, with a lot more features, which could mean it's not safe anymore. But I don't see any explicit acknowledgement in the release notes that it's now considered unsafe. regards, tom lane
I wrote: > I am not sure if this is a bug or an intentional change on their part. > Apparently "clock" was completely rewritten in 8.5, with a lot more > features, which could mean it's not safe anymore. But I don't see > any explicit acknowledgement in the release notes that it's now > considered unsafe. Oh, this is interesting: tclInterp.c's SlaveCreate() has a special purpose hack now: /* * The [clock] command presents a safe API, but uses unsafe features in * its implementation. This means it hasto be implemented in safe interps * as an alias to a version in the (trusted) master. */ if (safe) {Tcl_Obj *clockObj;int status; TclNewLiteralStringObj(clockObj, "clock");Tcl_IncrRefCount(clockObj);status = AliasCreate(interp, slaveInterp, masterInterp,clockObj, clockObj, 0, NULL);Tcl_DecrRefCount(clockObj);if (status != TCL_OK) { goto error2;} } So apparently it's still *supposed* to work, but there's something about the way we are using tcl that makes it not work. Any tcl experts in the house? regards, tom lane
Kyle Bateman <kyle@actarg.com> writes: > Is this a regression or is there a reason the clock command is no longer > accessible? And the answer is ... it's an underdocumented implementation change in Tcl's "clock" command. You can find the explanation and patch at http://archives.postgresql.org/pgsql-committers/2010-01/msg00369.php Or, if you just need a quick workaround, use pltclu. regards, tom lane