pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pltcl: missing close-brace
2+ messages / 2 participants
[nested] [flat]

* pltcl: missing close-brace
@ 2000-12-01 00:50  Jonathan Ellis <jellis@advocast.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Jonathan Ellis @ 2000-12-01 00:50 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

I have a pl/tcl function that doesn't work, but the same function in a
plain-vanilla tcl script does.  (The function emulates Oracle's "replace"
function.)

The PL/TCL results:

bf2=# create function replace2 (varchar, varchar, varchar) returns varchar
as '
    regsub -all {&} "$3" {\\\&} 3
    regsub -all {\\[0-9]} "$3" {\\\0} 3
    eval "regsub -all \{$2\} \{$1\} \{$3\} rval"
    return $rval
' language 'pltcl';

bf2'# bf2'# bf2'# bf2'# bf2'# CREATE

bf2=# select replace2('a b', ' ', 'c');
ERROR:  pltcl: missing close-brace

The plain tcl results:

#!/usr/bin/tcl

proc replace { 1 2 3 } {
    regsub -all {&} "$3" {\\\&} 3
    regsub -all {\\[0-9]} "$3" {\\\0} 3
    eval "regsub -all \{$2\} \{$1\} \{$3\} rval"
    return $rval
}

puts [replace "a b" " " "c"]

$ ./test.tcl
acb

Any idea what this error message means?

-Jonathan




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

* Re: pltcl: missing close-brace
@ 2000-12-01 04:46  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Jonathan Ellis <jellis@advocast.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2000-12-01 04:46 UTC (permalink / raw)
  To: Jonathan Ellis <jellis@advocast.com>; +Cc: pgsql-general@postgresql.org

"Jonathan Ellis" <jellis@advocast.com> writes:
> I have a pl/tcl function that doesn't work, but the same function in a
> plain-vanilla tcl script does.  (The function emulates Oracle's "replace"
> function.)

> bf2=# create function replace2 (varchar, varchar, varchar) returns varchar
> as '
>     regsub -all {&} "$3" {\\\&} 3
>     regsub -all {\\[0-9]} "$3" {\\\0} 3
>     eval "regsub -all \{$2\} \{$1\} \{$3\} rval"
>     return $rval
> ' language 'pltcl';

Those backslashes all need to be protected by backslashes ...
the SQL parser will strip off one level of backslashing as it parses
the command.

			regards, tom lane



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


end of thread, other threads:[~2000-12-01 04:46 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-12-01 00:50 pltcl: missing close-brace Jonathan Ellis <jellis@advocast.com>
2000-12-01 04:46 ` 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