Why does TRIM() expect an expr_list?

From: Korry Douglas <korry(dot)douglas(at)enterprisedb(dot)com>
To: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Why does TRIM() expect an expr_list?
Date: 2010-04-20 16:00:23
Message-ID: 7E289F92-9BC3-45E9-8495-81BE91FC9A68@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2010-04-20 16:24:21 Re: perltidy
Previous Message Robert Haas 2010-04-20 15:39:11 should I post the patch as committed?