List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 10 1999 7:22pm
Subject:Does this SUBSTRING() syntax seem strange to you?
View as plain text  
One of the SUBSTRING() variants supported by MySQL is:

SUBSTRING(str FROM len)

That looks weird to me.  FROM connotes that it should refer to a position,
not a length, as in one of the other variants:

SUBSTRING(str FROM pos FOR len)

But the first variant does indeed seem to treat len as a length and not
a position, returning the rightmost len characters.  For example,

SUBSTRING("abcdef" FROM 2) is "ef"

On the other hand, an appendix in the online Postgres docs gives the syntax
like this:

<character substring function> ::=
            SUBSTRING <left paren> <character value expression>
                       FROM <start position>
                       [ FOR <string length> ] <right paren>

That also implies the value following FROM should be a position, not a length.
How can I resolve this inconsistency?

-- 
Paul DuBois, paul@stripped
Thread
Does this SUBSTRING() syntax seem strange to you?Paul DuBois10 Aug
  • Re: Does this SUBSTRING() syntax seem strange to you?Thimble Smith11 Aug
  • Re: Does this SUBSTRING() syntax seem strange to you?Ken Farwell11 Aug
    • Re: Does this SUBSTRING() syntax seem strange to you?(Ray Zimmerman)11 Aug
  • Re: Does this SUBSTRING() syntax seem strange to you?Ken Farwell11 Aug
  • Does this SUBSTRING() syntax seem strange to you?Michael Widenius17 Aug