Re: MySQL insert() and instr() equiv

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Constable <markc(at)renta(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: MySQL insert() and instr() equiv
Date: 2006-06-17 16:33:37
Message-ID: 15857.1150562017@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mark Constable <markc(at)renta(dot)net> writes:
> uid is an email address stored in the passwd table as user(at)domain(dot)com
> and this construct allows an incoming username such as "user.domain.com"
> to be compared to the stored "user(at)domain(dot)com".
> SELECT wpath FROM passwd WHERE uid="\L" OR insert(uid,instr(uid,'@'),1,'.')="\L"

Well, if you want to write it exactly that way you'd need to write
insert() and instr() functions, which would probably take about five
minutes in any reasonably decent string-mashing language such as plperl.
You could do it in plpgsql but it'd be more painful. (There's an
example of coding instr() in the back of the plpgsql manual chapter,
but it's intended to match Oracle's version of instr() which might not
be quite like MySQL's.)

But, if you're not wedded to that particular way, why not use replace()?

SELECT wpath FROM passwd WHERE uid="\L" OR replace(uid, '@', '.')="\L"

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2006-06-17 16:49:22 Re: MySQL insert() and instr() equiv
Previous Message Mark Constable 2006-06-17 16:06:28 MySQL insert() and instr() equiv