Subject: operators

From: [email-masked] (J.Plewe)
Date: Thu, 30 Jun 94 13:23:50 +0200

I have defined a function to concatenate text-values 
in order to be abel to construct strings in the output:

  #define TEXT2CHAR(t,c) { strncpy(c,VARDATA(t),VARSIZE(t)-VARHDRSZ); \
  	c[VARSIZE(t)-VARHDRSZ] = '\0'; }

  text *textcat(text1,text2)
  text *text1, *text2;
  {
    text *res;
    char resbuf[512];
    char t2[256];

    TEXT2CHAR(text1,resbuf);
    TEXT2CHAR(text2,t2);

    strcat(resbuf,t2);
    res = (text*)palloc(strlen(resbuf) + VARHDRSZ + 1);

    VARSIZE(res) = strlen(resbuf) + VARHDRSZ;
    strcpy(VARDATA(res), resbuf);

    return res;
  }

------------------------------------------------------------------

  define function textcat( language="C",
                          returntype=text)
    arg is (text, text)
    as "/work/plewe/vis/mvd_connect.o"
  \g

  define operator $+ (
          arg1 = text,
          arg2 = text,
          procedure = textcat,
          associativity = any
          )
  \g      

------------------------------------------------------------------

So now I'm able to write:

  retrieve (x="Hello" $+ " world")

What I want to have work is:

  retrieve (x="Hello" $+ " world," $+ " what's on?")
  WARN:Jun 30 11:19:39:parser: syntax error at or near "$+"

I can help myself using brackets:

  Go 
  * retrieve (x=("Hello" $+ " world,") $+ " what's on?") \g

  Query sent to backend is "retrieve (x=("Hello" $+ " world,") $+ " what's on?")   "
  ---------------
  | x           |
  ---------------
  | Hello world, what's on?|
  ---------------

How do I have to define the operator '$+' to work like '+' does?
I admit that I do not understand the meanings of all the options of 
'define operator'.

Thank you,

- Joerg

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "[email-masked]"

   If this fails, send mail to "[email-masked]" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================