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

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function
Дата
Msg-id CAKFQuwbhT2NJKi2T3XH9drXu=5kGDMvPQOH2TKTbf9B8Q8uOfg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function  (Charles Clavadetscher <clavadetscher@swisspug.org>)
Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function  (Jerry Sievers <gsievers19@comcast.net>)
Список pgsql-general
On Sat, Jun 20, 2015 at 10:56 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"David G. Johnston" <david.g.johnston@gmail.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.


​The use of SELECT is required and will likely have a CTE and a set of SQL CASE expressions as part of it.
It isn't a problem to declare it myself but I thought I had read about there being an implicit variable name that could be used instead.  I guess I mis-remembered...

​Thanks for the quick response.

David J.


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function
Следующее
От: Charles Clavadetscher
Дата:
Сообщение: Re: Trying to avoid a simple temporary variable declaration in a pl/pgsql function