concatenation in procedures. - Mailing list pgsql-general

From Shaun Thomas
Subject concatenation in procedures.
Date
Msg-id Pine.LNX.4.33L2.0109131106180.2334-100000@hamster.lee.net
Whole thread Raw
List pgsql-general
So... this may sound stupid, but according to the documentation I've
read, this should be possible.

Why can I do this:

tError := ''Here is some error text.  I wanted to wrap it '' ||
          ''so my code would look nicer.  So, I of course '' ||
          ''thought of concatenation. '';
RAISE EXCEPTION ''%'', tError;

But I can't do this:

RAISE EXCEPTION ''Here is some error text.  I wanted to wrap it '' ||
                ''so my code would look nicer.  So, I of course '' ||
                ''thought of concatenation. '';

And yet the documentation uses this as an example:

RAISE EXCEPTION ''View '' || key || '' not found'';

So I made up an example to test this:

CREATE FUNCTION sp_test()
RETURNS BOOLEAN AS '
  DECLARE
    tStuff VARCHAR(10) := ''Print Me'';
  BEGIN
    RAISE EXCEPTION ''I would like to say : '' || tStuff || '', now!'';
    RETURN TRUE;
  END;
' LANGUAGE 'plpgsql';

Postgres returns this error:

mydb=# SELECT sp_test();
NOTICE:  plpgsql: ERROR during compile of sp_test near line 4
ERROR:  parse error at or near "|"

Which told me it was whining about the ||'s.  So I wrote this:

CREATE FUNCTION sp_test()
RETURNS BOOLEAN AS '
  DECLARE
    tStuff VARCHAR(10) := ''Print Me'';
  BEGIN
    RAISE EXCEPTION ''I would like to say : %, now!'', tStuff;
    RETURN TRUE;
  END;
' LANGUAGE 'plpgsql';

Which returns no errors, and runs as expected.

I first noticed this error in 7.1.1, but it's still around in 7.1.3.
What's the deal?

--
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Shaun M. Thomas                INN Database Programmer              |
| Phone: (309) 743-0812          Fax  : (309) 743-0830                |
| Email: sthomas@townnews.com    AIM  : trifthen                      |
| Web  : hamster.lee.net                                              |
|                                                                     |
|     "Most of our lives are about proving something, either to       |
|      ourselves or to someone else."                                 |
|                                           -- Anonymous              |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+




pgsql-general by date:

Previous
From: "Thurstan R. McDougle"
Date:
Subject: Re: count of occurences PLUS optimisation
Next
From: Ryan Mahoney
Date:
Subject: Re: business perspective