Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function
Date: 2015-06-20 14:56:44
Message-ID: 44911.1434812204@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> I know this could be written quite easily in sql but was wondering if it is
> possible in pl/pgsql.

> CREATE FUNCTION test_func()
> RETURNS text
> LANGUAGE 'plpgsql'
> AS $$
> BEGIN
> SELECT 'text_to_return' INTO <what_goes_here?>; --with or without a cast
> RETURN <what_goes_here?>;
> END;
> $$;

> The goal is to return the value of text_to_return without declaring an
> explicit variable to name in the INTO clause.

INTO requires a declared variable as target.

However, I'm wondering why you don't just use "RETURN expression"
if this is all that will be in the function.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2015-06-20 15:07:38 Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function
Previous Message David G. Johnston 2015-06-20 14:23:41 Trying to avoid a simple temporary variable declaration in a pl/pgsql function