Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, to do anything with your result set in <code>print_result</code> you'll have to loop over it. That'll look something like this - </p> <p>Here <code>result_record</code> is defined as a <code>record</code> variable. For the sake of explanation, we'll also assume that you have a <code>formatted_results</code> variable that is defined as <code>text</code> and defaulted to a blank string to hold the formatted results.</p> <pre><code>FOR result_record IN SELECT * FROM query_result(this_query) AS t (id int) LOOP -- With all this, you can do something like this formatted_results := formatted_results ||','|| result_record.id; END LOOP; RETURN formatted_results; </code></pre> <p>So, if you change <code>print_results</code> to return text, declare the variables as I've described and add this in, your function will return a comma-separated list of all your results (with an extra comma at the end, I'm sure you can make use of PostgreSQL's <a href="http://www.postgresql.org/docs/8.4/static/functions-string.html" rel="nofollow">string functions</a> to trim that). I'm not sure this is exactly what you want, but this should give you a good idea about how to manipulate your result set. You can get more information <a href="http://www.postgresql.org/docs/8.4/static/plpgsql-control-structures.html" rel="nofollow">here</a> about control structures, which should let you do pretty much whatever you want. </p> <p>EDIT TO ANSWER THE REAL QUESTION:</p> <p>The ability to format data tuples as readable text is a feature of the psql client, not the PostgreSQL server. To make this feature available in the server would require extracting relevant code or modules from the psql utility and recompiling them as a database function. This seems possible (and it is also possible that someone has already done this), but I am not familiar enough with the process to provide a good description of how to do that. Most likely, the best solution for formatting query results as text will be to make use of PostgreSQL's string formatting functions to implement the features you need for your application.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload