Re: Re: position('' in '') returns 1 instead of 0

From: Hiroshi Inoue <Inoue(at)tpf(dot)co(dot)jp>
To: Terry Carlin <terry(at)greatbridge(dot)com>
Cc: lockhart(at)fourpalms(dot)org, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Re: position('' in '') returns 1 instead of 0
Date: 2001-04-19 23:32:41
Message-ID: 3ADF7599.C238E185@tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Terry Carlin wrote:
>
> I was wrong about the locate() function in the odbc driver. Thomas
> Lockhart pointed out that it mapped locate in the driver to strpos in
> postgres. This tweaked a memory. What happens with the locate() odbc
> function in the odbc test suite is that it calls locate with the
> following arguments: locate(string, string, position). When this maps
> over to the strpos function, it fails as the strpos function only expects
> arguments like: strpos(string, string).
>
> benchmark=# \df strpos
> List of functions
> Result | Function | Arguments
> ---------+----------+------------
> integer | strpos | text, text
> (1 row)
>
> I had added a piece of functionality to the odbc.sql script that
> overloaded the strpos function like this:
>
> CREATE FUNCTION strpos(text,text,integer)
> RETURNS integer
> AS 'SELECT position($1 in substring($2 from $3))'
> LANGUAGE 'SQL';
>

Oh that explains it.
However the spec of locate() isn't clear to me.

LOCATE(string_exp1, string_exp2[, start]) (ODBC 1.0)

Returns the starting position of the first occurrence of string_exp1
within string_exp2. The search for the first occurrence of string_exp1
begins with the first character position in string_exp2 unless the
optional argument, start, is specified. If start is specified, the
search begins with the character position indicated by the value of
start. The first character position in string_exp2 is indicated by the
value 1. If string_exp1 is not found within string_exp2, the value 0 is
returned.

regards,
Hiroshi Inoue

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Joseph Crawley 2001-04-20 00:10:49 table named primary
Previous Message Peter Eisentraut 2001-04-19 20:48:11 Re: [HACKERS] Re: three VERY minor things with 7.1 final