I did not fully understand how to do the following: I have a sign with the object "book". Each book is marked with several sections (tags, as on hashcode.ru). Sections are stored on a single line, separated by spaces. I need to make a request in which a given author will display sections and their number. As I understand it, you should do something like this:
- We make a request for a table of books for a match by the name of the author, in which we select all sections of the books. Approximately it looks like this:
SELECT string_to_array(tags, " " FROM book WHERE author = 'Иван Иванов';, then pass the result totags_chart. - Then we implement the f-
tags_chart. This will be the usual pl / pgsql function.
You can write it like this:
CREATE OR REPLACE FUCNTION tags_chart(SETOF character)) RETURNS SETOF record AS '...' LANGUAGE pl/pgsql; The question is how to implement a mechanism for counting the number of elements. Solution in the forehead to create a record, label - the number, and walk through all the elements, while finding the label in the records to increase the number. But as it seems to me, this is not true. Here the complexity is O (n ^ 2). With the condition that I need to choose not everything, but only the first n marks of the author, the feeling that the task should be solved differently.