pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
clock command regression in pltcl?
4+ messages / 2 participants
[nested] [flat]

* clock command regression in pltcl?
@ 2010-01-23 04:41  Kyle Bateman <kyle@actarg.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Kyle Bateman @ 2010-01-23 04:41 UTC (permalink / raw)
  To: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: clock command regression in pltcl?
@ 2010-01-23 06:26  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Kyle Bateman <kyle@actarg.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Tom Lane @ 2010-01-23 06:26 UTC (permalink / raw)
  To: Kyle Bateman <kyle@actarg.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: clock command regression in pltcl?
@ 2010-01-23 06:50  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2010-01-23 06:50 UTC (permalink / raw)
  To: Kyle Bateman <kyle@actarg.com>; +Cc: pgsql-sql

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 has to 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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: clock command regression in pltcl?
@ 2010-01-25 02:17  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Kyle Bateman <kyle@actarg.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Tom Lane @ 2010-01-25 02:17 UTC (permalink / raw)
  To: Kyle Bateman <kyle@actarg.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2010-01-25 02:17 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-01-23 04:41 clock command regression in pltcl? Kyle Bateman <kyle@actarg.com>
2010-01-23 06:26 ` Tom Lane <tgl@sss.pgh.pa.us>
2010-01-23 06:50   ` Tom Lane <tgl@sss.pgh.pa.us>
2010-01-25 02:17 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox