Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-dev] three-args LOCATE function replacement using STRPOS and SUBSTRING on Postgres

Hi James,

As Symfoware also doesn't have a three-args LOCATE function I considered
doing something equivalent to what you implemented for Postgres:

LOCATE (a, b, i) ->
(STRPOS(SUBSTRING( a FROM i ), b ) + (i - 1))

But doesn't this give a wrong value when a does not include b?

Example:
a = "James"
b = "me"
i = 4

LOCATE (a, b, i) should return 0 as the search starts at 'e' in "James".
(STRPOS(SUBSTRING( a FROM i ), b ) + (i - 1)) would return 0 + (4 - 1) = 3.

So I figured it wouldn't work on Symfoware. Don't you have this issue on
Postgres?

I'm going to try the following on Symfoware, which is similar to what is
discussed on the mailing list:

COALESCE(NULLIF(POSITION(NULLIF(tofind,' ') IN SUBSTRING(string_exp FROM
startpos)), 0) - 1 + startpos, 0)

http://www.mail-archive.com/jboss-development@xxxxxxxxxxxxxxxxxxxxx/msg27548.html

Thanks,
Dies



Back to the top