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

Support for EXISTS as a select expression #5491

Open
joshkel opened this issue Feb 16, 2023 · 0 comments
Open

Support for EXISTS as a select expression #5491

joshkel opened this issue Feb 16, 2023 · 0 comments

Comments

@joshkel
Copy link

joshkel commented Feb 16, 2023

Environment

Knex version: 2.4.2
Database + version: Postgres 14.7
OS: macOS

Feature discussion / request

I see that Knex supports whereExists and whereNotExists, but I don't see how to use EXISTS as a select column expression. For example, something like the following:

select *,
   exists (select * from order where order.person_id = people.id) as has_orders
   from people;

Perhaps the usage would look something like this (modeled after count and whereExists).

knex('people').exists(function() {
  this.select('*').from('order').where('person_id', this.ref('people.id');
}, { as: 'has_orders' });

Alternatively, it could take its alias_name as the first parameter, as window functions like row_number do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant