Problem with LEFT function...
I wonder if I'm not facing to a bug in PostgreSQL.
I defined for convenience a LEFT function like this :
----------------------------------------------------------------------------
----------------------------
CREATE OR REPLACE FUNCTION LEFT( text, int) RETURNS text AS '
DECLARE
_STRori ALIAS FOR $1;
_INTlength ALIAS FOR $2;
BEGIN
RETURN SUBSTRING( _STRori, 1, _INTlength );
END'
LANGUAGE 'plpgsql';
----------------------------------------------------------------------------
----------------------------
Then I want to use this function in SQL statements.
SELECT LEFT( 'String1', 3 ) -> Str
SELECT LEFT( 'String1', 3 ) || 'End' -> StrEnd
SELECT 'Begin' || SUBSTRING( 'String1', 1, 3 ) -> BeginStr
BUT
SELECT 'Begin' || LEFT( 'String1', 3 ) -> ERROR: parser: parse error at or
near "LEFT"
Perhaps I misunderstood something but it seems there is a problem in
PostgreSQL parser.
My version is : PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96.
Patrick Fiche
email : patrick.fiche@aqsacom.com
t�l : 01 69 29 36 18
"Patrick Fiche" <patrick.fiche@aqsacom.com> writes:
SELECT 'Begin' || LEFT( 'String1', 3 ) -> ERROR: parser: parse error at or
near "LEFT"
Use a different function name. LEFT is a reserved word, and while PG
will let you get away with using it as a function name anyway, there
are situations like this where the normal interpretation of the keyword
takes precedence.
I've tweaked the grammar for 7.3 so that this particular case works,
but you'd still have similar problems if you were to use, say, BETWEEN
as a function name.
regards, tom lane