From a table of point data, there are some groups of points that can define a line (cross sections of a water course). 'cross_section' is the name of the table with the point data, geometrypoint the column with the geometry. 'code_sequence_nr' is the column that specifies the point sequence, so it becomes a nice line.
To make lines from groups of point data I have the following query:

CREATE TABLE cross_section_lines AS
SELECT st_makeline(geometrypoint) as cross_section,
cross_section.profile_code,
cross_section.administrative_area_id,
FROM (SELECT geometrypoint, profile_code, administrative_area_id
FROM cross_section
ORDER BY code_sequence_nr) cross_section
GROUP BY cross_section.profile_code, cross_section.administrative_area_id;

Now I need more information than the columns used for grouping, but if I add a column like this:

CREATE TABLE cross_section_lines AS
SELECT st_makeline(geometrypoint) as cross_section,
cross_section.profile_code,
cross_section.administrative_area_id,
cross_section.profile_type_id
FROM (SELECT geometrypoint, profile_code, administrative_area_id
FROM cross_section
ORDER BY code_sequence_nr) cross_section
GROUP BY cross_section.profile_code, cross_section.administrative_area_id;

Unfortunately that didn't do the trick: ProgrammingError: (psycopg2.errors.GroupingError) column "cross_section.profile_type_id" must appear in the GROUP BY clause or be used in an aggregate function
– Rob RikkenMay 23 at 9:57

That would work for the profile code, because that's the same for the whole profile. But there are other columns that are not the same for the whole profile. In that case the line would be split in however many groups there are of that item.
– Rob RikkenMay 23 at 10:06

2

In this case, you need to add to your question the INPUT - structure of your source table and an example of its content and OUTPUT what you would like to get...
– CyrilMay 23 at 10:11

That's probably true. This is my first question on stackexchange, so I was not really sure how much information people need to figure out a question :) .
– Rob RikkenMay 23 at 12:12