Re: problem with plpgsql function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: gav <gav(at)nlr(dot)ru>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: problem with plpgsql function
Date: 2000-08-11 15:36:52
Message-ID: 2418.966008212@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alex Guryanow <gav(at)nlr(dot)ru> writes:
> CREATE FUNCTION all_isbn2( int4 ) RETURNS varchar AS 'DECLARE
> i isbn%ROWTYPE;
> res varchar;
> BEGIN res := "";
> FOR i IN SELECT * FROM isbn WHERE isbn.book_id = $1 LOOP
> res := res || i.isbn;
> END LOOP;
> RETURN res;
> END;' LANGUAGE 'plpgsql';

> ERROR: Attribute '' not found

> What I'm doing wrong?

You need to write
BEGIN res := '''';
Double quotes "" imply a variable or column name, not a string literal.
You need 4 quotes not 2 because you're inside a ' literal already
(you could also write res := \'\' if that seems clearer).

It occurs to me that we ought to make a push to consistently use
double-quotes not single-quotes in error messages that are reporting
names. If the error had been
ERROR: Attribute "" not found
you might've figured out your mistake without help...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-08-11 15:41:11 Re: NOTIFY from PL/pgSQL trigger procedure
Previous Message Tom Lane 2000-08-11 15:29:04 Re: insert into table from select..