Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for json_agg_strict (PostgreSQL only) #892

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

leibale
Copy link

@leibale leibale commented Feb 29, 2024

Add support for json_agg_strict (PostgreSQL only) - this function is just like json_agg, but skips null (see https://www.postgresql.org/docs/current/functions-aggregate.html)

A few notes:

  1. I've duplicated all json_agg tests and changed them to use json_agg_strict, but I'm not sure if:
    1. Should we test all cases for both json_agg and json_agg_strict?
    2. If we want to fully test both, do you prefer duplicating the code, using a loop, or using a function?
  2. json_agg might return null (for example, when using left join and there is nothing to join with), but the types ignore that.. I guess fixing it is a breaking change, so I did not include it in this PR

Thanks for this awesome package! :)

Copy link

vercel bot commented Feb 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 21, 2024 10:28am

@leibale
Copy link
Author

leibale commented Mar 1, 2024

When using it with left join every field becomes nullable (I think that left join changes DB[table] to a "nullable version"), which is not true for json_agg (which will reply with [null] for "empty join", or json_agg_strict (which will reply with [] for "empty join").
I'm not too sure if this will be easy to solve.. any help will be appreciated :)

@igalklebanov igalklebanov added enhancement New feature or request postgres Related to PostgreSQL api Related to library's API labels Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request postgres Related to PostgreSQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants