473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PostgreSQL equivalent to MySQL LOCATE()

Hi

I am looking for an equivalent to the LOCATE function from MySQL.
I have a query(PHP) that looks like this:

Expand|Select|Wrap|Line Numbers
  1. $query="SELECT * FROM table WHERE LOCATE('".$var."', field)> 0 ORDER BY LOCATE('".$var."', field) LIMIT 10";
Any Ideas?
Sep 19 '07 #1
4 17291
rski
700 Expert 512MB
Hi

I am looking for an equivalent to the LOCATE function from MySQL.
I have a query(PHP) that looks like this:

Expand|Select|Wrap|Line Numbers
  1. $query="SELECT * FROM table WHERE LOCATE('".$var."', field)> 0 ORDER BY LOCATE('".$var."', field) LIMIT 10";
Any Ideas?
I do not know mysql, but does LOCATE work as regular expressions. If so u can use postgres LIKE (or ILIKE) statement.
Sep 20 '07 #2
This may be a little late, but if I got here from a Google search, other people will, too. So here's an answer:

MySQL locate('substring','long string containing substring')
is equivalent to
PostgreSQL position('substring' IN 'long string containing substring')
Oct 17 '10 #3
I am having a similar problem.

However I wish to use this form:
LOCATE(substr,str,pos)

Can someone offer me a way too do this in postgresql?
(as 'position' does not contain the 'pos' function)

Thanks.
Dec 13 '10 #4
rski
700 Expert 512MB
You can use
Expand|Select|Wrap|Line Numbers
  1. strpos(string, substring)
  2.  
but it takes only two arguments.

You can use strpos with substr and it works lile locate
Expand|Select|Wrap|Line Numbers
  1. locate(to_find,str,pos)=strpos(substr(str,pos),to_find)
  2.  
Dec 14 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Marek Lewczuk | last post by:
Hello group, For everyone who thinks about moving from MySQL to PostgreSQL I have a realy bad news - It's not worth. Why, You may ask... A few days ago I have installed and tested PostgreSQL,...
0
by: packrat | last post by:
I am attempting to build a Bugzilla server on OS X. All of this is new to me, working with the Perl, MySQL, and Bugzilla, so I have been banging my head often. Software error: When I run the...
33
by: Joshua D. Drake | last post by:
Hello, I think the below just about says it all: http://www.commandprompt.com/images/mammoth_versus_dolphin_500.jpg Sincerely, Joshua Drake
74
by: John Wells | last post by:
Yes, I know you've seen the above subject before, so please be gentle with the flamethrowers. I'm preparing to enter a discussion with management at my company regarding going forward as either...
11
by: Errol Neal | last post by:
Hi all, Not sure if this is a question for a php list or this one, but I'll give it a shot and if I am wrong, please do not crucify me. :-) There is a php based sourceforge project called...
3
by: Marek Lewczuk | last post by:
Hello, I have changed DB from MySQL to PostgreSQL. When I have run my application on PostgreSQL it was disaster - it was much slower than MySQL... I have tried to change PG configuration file...
4
by: Chris Travers | last post by:
Hi all; A few years ago, I set about porting a PHP application from MySQL to PostgreSQL, after realizing that MySQL wasn't going to be able to handle it. In order to do this, I built a light,...
1
by: Richard Huxton | last post by:
On Thursday 12 February 2004 20:25, Prashanthi Muthyala wrote: > Hi Richard Hi Prashanthi - nice to hear from you again. I've taken the liberty of cc-ing the general list on this, since there...
6
by: Jay | last post by:
hi people i am trying to connect to ppstgresql on a debian system using perl . i am getting the following error .can any one please suggest what has to be done install_driver(pg) failed:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.