# Postgresql Functions

**URL:** https://discourse.rom-rb.org/t/postgresql-functions/347
**Category:** Issues
**Created:** [February 23, 2020, 8:43pm UTC](https://discourse.rom-rb.org/t/postgresql-functions/347 "2020-02-23T20:43:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![skinnyjames](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@skinnyjames](https://discourse.rom-rb.org/u/skinnyjames)
#### Post date: [February 23, 2020, 8:43pm UTC](https://discourse.rom-rb.org/t/postgresql-functions/347/1 "2020-02-23T20:43:35Z")

</div>

Hello, trying to construct the following query using ROM

```auto
select repos.*, 
           json_agg(row_to_json(reports.*)) as reports 
from repos 
left join reports on 
repos.id = reports.repo_id 
group by repos.id;

```

However when constructing the query I’m getting

```auto
undefined method `meta' for #<Module:0x00000000064a9830>
file: attribute.rb location: meta line: 309

```

and my query looks like

```auto
   select { [:id, :name, array::json_agg(json::row_to_json(:reports __id, :reports__ name))] }
    .left_join(reports, repo_id: :id).group(:id)

```

Anyone have any ideas?

---

<div class="post-metadata">

### Author: ![skinnyjames](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@skinnyjames](https://discourse.rom-rb.org/u/skinnyjames)
#### Post date: [February 24, 2020, 3:19am UTC](https://discourse.rom-rb.org/t/postgresql-functions/347/2 "2020-02-24T03:19:19Z")

</div>

was able to aggregate the rows into json, but cannot seem to filter the json\_agg using the filter function.

```auto
 select do 
       [:id, 
        :name, 
        string::coalesce(
          string::json_agg(
            string::json_build_object(
                'id',
                Sequel[:reports][:id],
                'name',
                Sequel[:reports][:name],
                'body',
                Sequel[:reports][:framework]
            )
          ),
          '[]'
        ).as(:reports),

```
