Re: variable value in array_to_string - Mailing list pgsql-general

From David G. Johnston
Subject Re: variable value in array_to_string
Date
Msg-id CAKFQuwaujAm+fSNP8NYXxVD-t7FKn81_9BY5+zmEj9q_S5VR+Q@mail.gmail.com
Whole thread Raw
In response to Re: variable value in array_to_string  ("Armand Pirvu (home)" <armand.pirvu@gmail.com>)
List 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.

pgsql-general by date:

Previous
From: "Armand Pirvu (home)"
Date:
Subject: Re: variable value in array_to_string
Next
From: Mark Anns
Date:
Subject: How to open PGStrom (an extension of PostgreSQL) in Netbeans?