Re: variable value in array_to_string

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "Armand Pirvu (home)" <armand(dot)pirvu(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: variable value in array_to_string
Date: 2016-11-22 01:58:57
Message-ID: CAKFQuwaujAm+fSNP8NYXxVD-t7FKn81_9BY5+zmEj9q_S5VR+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

For what its worth:

DO $$
DECLARE
vresult text;
begin
EXECUTE $qry$
WITH cols (c) AS ( VALUES ('col1'),('col2') )
SELECT string_agg('a.' || cols.c, ',')
FROM cols
WHERE 'foo' = $1
$qry$
USING 'foo'
INTO vresult;
RAISE NOTICE '%', vresult;
END;
$$;

I still haven't actually figured out what your question is which is maybe
why I'm coming across as patronizing. And while I get that what you wrote
is technically correct its using capabilities that have since be superseded
by more readable and less error-prone facilities.

The docs do explain this material in terms of technical capabilities. For
better and worse it doesn't always go to great lengths (or keeps up with
changing times) to describe best practices or how multiple pieces fit
together.

​I'm also thinking that your original question is more accurately worded:
Is there anyway I can [use an expression] in the array_to_string function

I'm not nit-picking here - the word variable when you writing a pl/pgsql
language function has a very specific meaning which is not <'a.' ||
column_name>

In both cases the answer is a simple yes. Sorry for causing pain by
offering up more information than requested. Its bad habit of mine -
trying to provide related information when presented with a question.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message MEERA 2016-11-22 06:23:05 Methods to quiesce PostgreSQL DB without configuring log archival
Previous Message Armand Pirvu (home) 2016-11-22 01:33:37 Re: variable value in array_to_string