# How to write relative to a user in code inside SQl (Postgresql) Custom query

**URL:** https://community.glideapps.com/t/how-to-write-relative-to-a-user-in-code-inside-sql-postgresql-custom-query/72950
**Category:** Ask for Help
**Tags:** sql
**Created:** [April 30, 2024, 11:05am UTC](https://community.glideapps.com/t/how-to-write-relative-to-a-user-in-code-inside-sql-postgresql-custom-query/72950 "2024-04-30T11:05:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Bilol](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bilol/32/61455_2.png) [@Bilol](https://community.glideapps.com/u/Bilol)
#### Post date: [April 30, 2024, 11:05am UTC](https://community.glideapps.com/t/how-to-write-relative-to-a-user-in-code-inside-sql-postgresql-custom-query/72950/1 "2024-04-30T11:05:18Z")

</div>

I need to create a report for each employee;

the main database is in SQL (Postgresql) and the table with users is in the Glide table itself

Problem:

- If the report is made on the user’s table, then the calculated columns do not work (Rollup)

- if you do it in SQL inside glide (Custom query), I don’t know how to access the users table in code and make everything work relative to users

---

<div class="post-metadata">

### Author: ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)
#### Post date: [April 30, 2024, 11:47am UTC](https://community.glideapps.com/t/how-to-write-relative-to-a-user-in-code-inside-sql-postgresql-custom-query/72950/2 "2024-04-30T11:47:02Z")

</div>

> [@Bilol](#):
>
> if you do it in SQL inside glide (Custom query), I don’t know how to access the users table in code

I don’t think you can make the custom query dynamic or user specific. The custom query in the glide table needs to be static

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [April 30, 2024, 11:52pm UTC](https://community.glideapps.com/t/how-to-write-relative-to-a-user-in-code-inside-sql-postgresql-custom-query/72950/3 "2024-04-30T23:52:23Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/c/3ca704f2aa8c7c47716e60a2e65b8a36138c73ff.png)

Do you know if this works in SQL or the enhancement is only for Big Tables?

---

<div class="post-metadata">

### Author: ![Bilol](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bilol/32/61455_2.png) [@Bilol](https://community.glideapps.com/u/Bilol)
#### Post date: [May 1, 2024, 9:48am UTC](https://community.glideapps.com/t/how-to-write-relative-to-a-user-in-code-inside-sql-postgresql-custom-query/72950/4 "2024-05-01T09:48:29Z")

</div>

I haven’t dealt with Big Tables  
you can read about SQL in the documentation

> **[Introduction to Data Sources | Glide Docs](https://www.glideapps.com/docs/essentials/data-sources)**
>
> Discover how to connect your data to your Glide app

I have a lot of inconvenience with SQL especially with calculations

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [May 1, 2024, 12:53pm UTC](https://community.glideapps.com/t/how-to-write-relative-to-a-user-in-code-inside-sql-postgresql-custom-query/72950/5 "2024-05-01T12:53:25Z")

</div>

Sorry, I meant to reply to Eric to ask for his opinion, since I’m not familiar with SQL and can ask the team to update the documentation if needed.

---

<div class="post-metadata">

### Author: ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)
#### Post date: [May 2, 2024, 1:53am UTC](https://community.glideapps.com/t/how-to-write-relative-to-a-user-in-code-inside-sql-postgresql-custom-query/72950/6 "2024-05-02T01:53:34Z")

</div>

Hey @ThinhDinh my experience is limited to playing around with BigQuery. I learned back then you can’t make a query dynamic either through a template column or user specific column… so I didn’t use it in my solution.

I think some of the limitations can be worked around with a matter of creativity… I.e. calculating some value beforehand and then add that static value to a basic column in your table.

Some cases you can feed a joined list through a JS column to get an answer.

When I have time to try it further I will circle back with you 👍
