Обсуждение: position(text,text) function

Поиск
Список
Период
Сортировка

position(text,text) function

От
karl@tecc.co.uk (Karl Orbell)
Дата:
I'm having trouble using the position function, it's a simple built-in function.

It returns the index of a substring within a main string.

But, I just can't get it to work, it always gives this silly parser error.
I've tried it in a variety of ways with variables instead of constants casting 
to text and using it in other contexts, (ie. in functions, not just in a 
select).  What am I doing wrong?  Is this not the correct syntax for a two 
argument function?

test=# select position('hello','el');
ERROR:  parser: parse error at or near ","


Karl Orbell.



RE: position(text,text) function

От
Jeff Eckermann
Дата:
You are confusing the syntax of two similar functions:
position ('substring' in 'string')
strpos ('string', 'substring').
I have a feeling that "position" actually calls "strpos", but I am guessing
on that.

> -----Original Message-----
> From:    karl@tecc.co.uk [SMTP:karl@tecc.co.uk]
> Sent:    Monday, July 23, 2001 9:27 AM
> To:    pgsql-sql@postgresql.org
> Subject:    position(text,text) function
> 
> I'm having trouble using the position function, it's a simple built-in
> function.
> 
> It returns the index of a substring within a main string.
> 
> But, I just can't get it to work, it always gives this silly parser error.
> I've tried it in a variety of ways with variables instead of constants
> casting 
> to text and using it in other contexts, (ie. in functions, not just in a 
> select).  What am I doing wrong?  Is this not the correct syntax for a two
> 
> argument function?
> 
> test=# select position('hello','el');
> ERROR:  parser: parse error at or near ","
> 
> 
> Karl Orbell.
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


Re: position(text,text) function

От
Dorin Grunberg
Дата:
<font size="3">The correct way would be:<br /><br /> select position('el' in 'Hello');<br /><br /> Dorin<br /><br /> At
02:27PM 7/23/01 +0000, Karl Orbell wrote:<br /><blockquote cite="cite" type="cite">I'm having trouble using the
positionfunction, it's a simple built-in function.<br /><br /> It returns the index of a substring within a main
string.<br/><br /> But, I just can't get it to work, it always gives this silly parser error.<br /> I've tried it in a
varietyof ways with variables instead of constants casting <br /> to text and using it in other contexts, (ie. in
functions,not just in a <br /> select).  What am I doing wrong?  Is this not the correct syntax for a two <br />
argumentfunction?<br /><br /> test=# select position('hello','el');<br /> ERROR:  parser: parse error at or near ","<br
/><br/><br /> Karl Orbell.<br /><br /><br /> ---------------------------(end of
broadcast)---------------------------<br/> TIP 1: subscribe and unsubscribe commands go to
majordomo@postgresql.org</blockquote></font><br/> 

Re: RE: position(text,text) function

От
"Josh Berkus"
Дата:
Jeff, Karl,

Actually, he's confusing 3 functions.  See postgresql.org --> user
lounge --> interactive docs --> functions and operators --> string
functions.

-Josh

> You are confusing the syntax of two similar functions:
> position ('substring' in 'string')
> strpos ('string', 'substring').
> I have a feeling that "position" actually calls "strpos", but I am
> guessing
> on that.
> 
> > -----Original Message-----
> > From: karl@tecc.co.uk [SMTP:karl@tecc.co.uk]
> > Sent: Monday, July 23, 2001 9:27 AM
> > To: pgsql-sql@postgresql.org
> > Subject: position(text,text) function
> > 
> > I'm having trouble using the position function, it's a simple
> built-in
> > function.
> > 
> > It returns the index of a substring within a main string.
> > 
> > But, I just can't get it to work, it always gives this silly parser
> error.
> > I've tried it in a variety of ways with variables instead of
> constants
> > casting 
> > to text and using it in other contexts, (ie. in functions, not just
> in a 
> > select).  What am I doing wrong?  Is this not the correct syntax
> for a two
> > 
> > argument function?
> > 
> > test=# select position('hello','el');
> > ERROR:  parser: parse error at or near ","
> > 
> > 
> > Karl Orbell.
> > 
> > 
> > ---------------------------(end of
> broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to
> majordomo@postgresql.org
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


Re: position(text,text) function

От
"omid omoomi"
Дата:
position ( 'el' in 'hello') ;

>From: karl@tecc.co.uk (Karl Orbell)
>To: pgsql-sql@postgresql.org
>Subject: [SQL] position(text,text) function
>Date: Mon, 23 Jul 2001 14:27:15 +0000 (UTC)
>
>I'm having trouble using the position function, it's a simple built-in 
>function.
>
>It returns the index of a substring within a main string.
>
>But, I just can't get it to work, it always gives this silly parser error.
>I've tried it in a variety of ways with variables instead of constants 
>casting
>to text and using it in other contexts, (ie. in functions, not just in a
>select).  What am I doing wrong?  Is this not the correct syntax for a two
>argument function?
>
>test=# select position('hello','el');
>ERROR:  parser: parse error at or near ","
>
>
>Karl Orbell.
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp



Re: position(text,text) function

От
karl@tecc.co.uk (Karl Orbell)
Дата:
Many thanks for all of the assistance on this question.

I can't say I've ever seen the "a in b" syntax in postgres, but
you live and learn. ;-)

Thanks again.

Karl.

In article <slrn9loctm.qsr.karl@azrael.tecc.co.uk>, Karl Orbell wrote:
> I'm having trouble using the position function, it's a simple built-in function.
> 
> It returns the index of a substring within a main string.
> 
> But, I just can't get it to work, it always gives this silly parser error.
> I've tried it in a variety of ways with variables instead of constants casting 
> to text and using it in other contexts, (ie. in functions, not just in a 
> select).  What am I doing wrong?  Is this not the correct syntax for a two 
> argument function?
> 
> test=# select position('hello','el');
> ERROR:  parser: parse error at or near ","
> 
> 
> Karl Orbell.
>