Why does TRIM() expect an expr_list? - Mailing list pgsql-hackers

From Korry Douglas
Subject Why does TRIM() expect an expr_list?
Date
Msg-id 7E289F92-9BC3-45E9-8495-81BE91FC9A68@enterprisedb.com
Whole thread Raw
Responses Re: Why does TRIM() expect an expr_list?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
In gram.y, the productions for the TRIM() expression expect an  
argument of trim_list:
TRIM '(' trim_list ')'TRIM '(' TRAILING trim_list ')'TRIM '(' LEADING trim_list ')'TRIM '(' BOTH trim_list ')'

And trim_list is defined as:
  trim_list:    a_expr FROM expr_list      { $$ = lappend($3, $1); }        | FROM expr_list            { $$ = $2; }
   | expr_list                { $$ = $1; }
 

But it seems wrong for trim_list to be defined in terms of  
expr_list's.  The way it's currently written, we allow expressions  
such as:
TRIM( 'foo', now(), 4+2)

or
TRIM( LEADING FROM 'foo', 4+2)

The parser translates the TRIM expression into a call to btrim() (or  
ltrim() or rtrim()) and we seem to (accidentally) make up a silly  
argument list if the user includes an actual expr_list (with multiple  
expressions).

The first example results in "function ltrim(unknown, timestamp with  
time zone, integer) does not exist".

The second example above is translated to ltrim(4+2, 'foo').

It seems to me that trim_list should defined as:
  trim_list:    a_expr FROM a_expr      { $$ = list_make2($3, $1); }        | FROM a_expr            { $$ =
list_make1($2);}        | a_expr                    { $$ = list_make1($1); }
 

Am I missing something?
    -- Korry


-----------------------------------------------------------------------
Korry Douglas
Senior Database Dude
EnterpriseDB Corporation
The Enterprise Postgres Company

Phone: (804)241-4301
Mobile: (620) EDB-NERD




pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: should I post the patch as committed?
Next
From: Bruce Momjian
Date:
Subject: Re: perltidy