Re: Position() Bug ? In PostgreSQL 9.2

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: dinesh kumar <dineshkumar02(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Position() Bug ? In PostgreSQL 9.2
Date: 2013-05-02 13:32:16
Message-ID: CA+HiwqFhO67as0ZE42QqFCyrCjb-jV38H8i9pHvsRxzor+zWuA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This behavior is similar to strstr(3) ('needle in a haystack'
substring locating C function).

char *strstr(const char *haystack, const char *needle)

which returns haystack (that is main string) if needle (string to be
located) is empty.

Assuming position() tries to do something similar, it returns first
index (which is 1) of the main string (haystack!). Although this does
not answer if it's a bug or not, I tend to think it is deliberate.

On Thu, May 2, 2013 at 9:09 PM, dinesh kumar <dineshkumar02(at)gmail(dot)com> wrote:
> Hello Team,
>
> I would like to know whether the following behavior is a BUG or an expected
> behavior. If this is a duplicated case, then kindly ignore.
>
> postgres=# SELECT version();
> version
> -------------------------------------------------------------
> PostgreSQL 9.2.3, compiled by Visual C++ build 1600, 32-bit
> (1 row)
>
>
> postgres=# select position('P' in 'PostgreSQL');
> position
> ----------
> 1
> (1 row)
>
>
> postgres=# select position('' in 'PostgreSQL'); // position(Substring as an
> empty string) is returning 1.
> position
> ----------
> 1
> (1 row)
>
> Kindly let me know, if anything i miss here.
>
> Regards,
> Dinesh
> manojadinesh.blogspot.com

--

Amit Langote

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2013-05-02 13:49:38 Re: Position() Bug ? In PostgreSQL 9.2
Previous Message Amit Langote 2013-05-02 13:25:28 Position() Bug ? In PostgreSQL 9.2