proposal: prefix function

Started by Pavel Stehuleover 7 years ago4 messages
#1Pavel Stehule
pavel.stehule@gmail.com

Hi

can we implement prefix function for fast test if substr is prefix of some
string?

create or replace function prefix(str text, substr text)
returns boolean as $$
select substr(str, 1, length(substr)) = substr
$$ language sql;

This function can be very effective in C language. Now it should be
implemented with like or regexp, what is significantly more expensive.

Regards

Pavel

#2Chris Travers
chris.travers@adjust.com
In reply to: Pavel Stehule (#1)
Re: proposal: prefix function

On Fri, Sep 21, 2018 at 10:09 AM Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hi

can we implement prefix function for fast test if substr is prefix of some
string?

create or replace function prefix(str text, substr text)
returns boolean as $$
select substr(str, 1, length(substr)) = substr
$$ language sql;

This function can be very effective in C language. Now it should be
implemented with like or regexp, what is significantly more expensive.

These would just be wrappers around already existing internal functions,
right?

Regards

Pavel

--
Best Regards,
Chris Travers
Head of Database

Tel: +49 162 9037 210 | Skype: einhverfr | www.adjust.com
Saarbrücker Straße 37a, 10405 Berlin

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Chris Travers (#2)
Re: proposal: prefix function

pá 21. 9. 2018 v 12:37 odesílatel Chris Travers <chris.travers@adjust.com>
napsal:

On Fri, Sep 21, 2018 at 10:09 AM Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hi

can we implement prefix function for fast test if substr is prefix of
some string?

create or replace function prefix(str text, substr text)
returns boolean as $$
select substr(str, 1, length(substr)) = substr
$$ language sql;

This function can be very effective in C language. Now it should be
implemented with like or regexp, what is significantly more expensive.

These would just be wrappers around already existing internal functions,
right?

maybe, I didn't do any research. If not, the implementation is on few lines.

Regards

Pavel

Show quoted text

Regards

Pavel

--
Best Regards,
Chris Travers
Head of Database

Tel: +49 162 9037 210 | Skype: einhverfr | www.adjust.com
Saarbrücker Straße 37a, 10405 Berlin

#4Pavel Stehule
pavel.stehule@gmail.com
In reply to: Chris Travers (#2)
Re: proposal: prefix function

Hi

pá 21. 9. 2018 v 12:37 odesílatel Chris Travers <chris.travers@adjust.com>
napsal:

On Fri, Sep 21, 2018 at 10:09 AM Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Hi

can we implement prefix function for fast test if substr is prefix of
some string?

create or replace function prefix(str text, substr text)
returns boolean as $$
select substr(str, 1, length(substr)) = substr
$$ language sql;

This function can be very effective in C language. Now it should be
implemented with like or regexp, what is significantly more expensive.

These would just be wrappers around already existing internal functions,
right?

It is already - I forgot

starts_with

It is PostgreSQL 11 feature 710d90da1fd8c1d028215ecaf7402062079e99e9

I like when I can do nothing :)

Pavel

Show quoted text

Regards

Pavel

--
Best Regards,
Chris Travers
Head of Database

Tel: +49 162 9037 210 | Skype: einhverfr | www.adjust.com
Saarbrücker Straße 37a, 10405 Berlin