why am i getting only the first row on my queries?
# help
d
why am i getting only the first row on my queries?
s
Can you provide more context please along with the code you are using?
Also please don't cross post between channels.
d
i need to query data from a jobs table and insert into a clients table, into two different columns.
first i grab the customer name to put on name column, then i grab the list of unpaid/partially paid jobs of the customer as an array of objects to put on the open_jobs column.
the code below works but it only returns the first row.
Copy code
sql
do $$
  declare
    x varchar;
    y json;
  begin
    select distinct customer
    into x
    from jobs
    order by customer asc;

    select array_to_json(array_agg(row_to_json(t)))
    from (
      select job_location, job_total, paid, invoice_no
      into y
      from jobs
      where customer = x and paid < job_total
      order by invoice_no asc
    )t;

    insert into clients(name, open_jobs)
    values(x, y);
  end;
$$ language plpgsql;
here's an image of the query result
sorry for cross posting but this is the first time ever i write sql code and i was hoping to rely on community help
and the sql channel doesn't seem to have much movement