Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Instr function doesnt work

Instr function doesnt work

Instr function doesnt work

Hi all, I am just trying to write stored funtion on PostgreSQL database with PG Admin III and find out a trouble.

This is my function, which shoul be use as ordinary String.Split :

-- Function: split_varchar_to_int(p_list "varchar", p_del "varchar")

-- DROP FUNCTION split_varchar_to_int(p_list "varchar", p_del "varchar");

CREATE OR REPLACE FUNCTION split_varchar_to_int(p_list varchar(30), p_del varchar(5))
  RETURNS iarray AS
    l_idx    integer;
    l_list   varchar;
    retValue iarray;
    i integer;
    l_list := p_list;
    i := 1;
        l_idx := instr(1,l_list,p_del,1);
        if l_idx > 0 then
            retValue[i] := (substr(l_list,1,l_idx-1));
            l_list := substr(l_list,l_idx+length(p_del));
            retValue[i] := (l_list);
        i := i + 1;
        end if;
    end loop;
return retValue;


ALTER FUNCTION split_varchar_to_int(p_list "varchar", p_del "varchar") OWNER TO postgres;

And this is how I call this function:

split_varchar_to_int('1;2;3;4;5', ';');

And this message is given to me:

ERROR:  function instr(character varying, character varying) does not exist
No function matches the given name and argument types. You may need to add explicit type casts.
SQL statement "SELECT  instr( $1 , $2 )"
PL/pgSQL function "split_varchar_to_int" line 14 at assignment

Could you please help me?Thank you.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close