Re: Newbie in functions

From: Chris <csmith(at)squiz(dot)net>
To: Eduardo_Cadena(at)praxair(dot)com, pgsql-novice(at)postgresql(dot)org
Subject: Re: Newbie in functions
Date: 2002-04-17 22:39:52
Message-ID: 5.1.0.14.0.20020418083158.00a9d5a0@cooee.cybersydney.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

>I´m trying to create a function to obtain the possition of a substring, but
>i don't kown if is correct
>can anyone can help me to do this?
>
>test=# CREATE FUNCTION pos1 (int4) RETURNS int4 AS '
>test'# UPDATE tabla1
>test'# SET posicion1 = position('pm' in SELECT string1 FROM tabla1 WHERE
>id = $1)
>test'# WHERE id = $1;
>test'# SELECT posicion1 FROM tabla1 WHERE id = $1;
>test'# 'LANGUAGE sql;
>ERROR: parser: parse error at or near "pm"
>test=#

This one's a fairly simple one. You need to escape the quote around pm, so
it turns into:

SET posicion1 = position(\'pm\' in SELECT string1 FROM tabla1 WHERE
.........

(This is because you're already inside the function which starts at the
first ' on the top line).

.. and you're not returning any values yet either :)

HTH,

-----------------
Chris Smith
http://www.squiz.net/

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2002-04-17 23:24:47 Re: cannot restore db
Previous Message Brian Scandale 2002-04-17 21:51:01 Re: Interval data types and SQL Server