declare variable in udf

From: Peter Kroon <plakroon(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: declare variable in udf
Date: 2012-11-21 11:42:52
Message-ID: CAOh+DOn=_zHjJyOyD_ERcFmMK8t6gv_kR-kCj78R6OnAxjBu7w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

How do I declare a variable after BEGIN?
I want to declare it in the if statement.

DROP FUNCTION IF EXISTS tmp_test(integer);
CREATE FUNCTION tmp_test(
p_id integer
)
RETURNS text
AS $$
DECLARE the_return_value text;
BEGIN
DROP TABLE IF EXISTS temp_test_table;
CREATE TEMP TABLE temp_test_table(
some_value text
);
INSERT INTO temp_test_table
SELECT data FROM table WHERE id=p_id;
SELECT INTO the_return_value some_value FROM temp_test_table;

IF 1=1 THEN
--how do I declare a variable here? it this possible?
RAISE NOTICE 'this is a notice';
END IF;

RETURN the_return_value;

END;
$$ language plpgsql

Best,
Peter

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2012-11-21 11:51:29 Re: declare variable in udf
Previous Message Ranjeet Dhumal 2012-11-21 11:23:25 ERROR: volatile EquivalenceClass has no sortref