question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional segments of queries

See original GitHub issue

Description

Minimal condition query segments would be useful, and can be based exclusively around named parameters or flag variables.

For example, two conditionals in this statement, one could just use the empty list without conditional although it makes a silly query, but the 2nd case requires the conditional.

selectPosts:
SELECT *
FROM posts
WHERE authorId NOT IN :muteUserList
	  AND category IN :categoryList
;

This is not intended as final syntax, but uses a tag plus Kotlin conditional that maybe helps code compilation to inject that code directly into the calling logic or as a lambda. Nesting might also be needed.

Of course you could write multiple queries, but large queries that have complex bases would be painful to maintain 4 or 5 copies for small variations.

You could use CTE’s if you could nest queries and then further refine it, but that doesn’t work in all cases such as those requiring a join and a where clause item, that have big impact on the primary query.

nesting queries maybe is another helpful flavor of this conditional or compound query structuring:

selectSomePosts:
SELECT *
FROM {{selectPosts}}
WHERE authorId NOT IN :muteUserList
 	  AND category IN :categoryList
;

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
apatridacommented, Aug 12, 2022

CASE is work around for some but not all issues (optional joins, subqueries, …)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional clauses | Dynamic queries - Drupal
A "conditional clause" is a portion of a query that restricts the rows matched by certain conditions. In SQL, that means the WHERE...
Read more >
Creating Conditional Statements in SQL Queries
Although SQL isn't a general-purpose language, it includes conditional statements with a similar structure to other languages.
Read more >
Query segmentation using conditional random fields
In this paper, we address the problem of keyword query segmentation, i.e., how to group nearby keywords in a query into segments. This...
Read more >
Create a custom condition and segmentation query
You can create a custom condition and segmentation query to identify contacts and enroll them into a marketing automation plan.
Read more >
Segment Query definition - Dynamics 365 - Microsoft Learn
Dynamic segments are based on segment query ( msdyncrm_segmentquery ). You can define a segment query by combing groups of logical ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found