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

Can we have IN filter? #2157

Closed
flowbehappy opened this issue Apr 3, 2015 · 35 comments
Closed

Can we have IN filter? #2157

flowbehappy opened this issue Apr 3, 2015 · 35 comments
Labels

Comments

@flowbehappy
Copy link

Hi! Great job for InfluxDB.

And I wonder If it can support IN filter in where clause, so far it seems no supported:

SELECT * FROM mydb WHERE service IN ('aa', 'bb');

{
    "error": "error parsing query: found IN, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, REVOKE, ALTER at line 1, char 321"
}

version: bdd469d

@otoolep
Copy link
Contributor

otoolep commented Apr 3, 2015

We don't have support for IN right now but you can use OR, for the query you provided:

SELECT * from mydb WHERE service = 'aa' OR service = 'bb'

@beckettsean beckettsean added this to the Next Point Release milestone Apr 8, 2015
@beckettsean beckettsean modified the milestones: Next Point Release, Longer term Aug 6, 2015
@otoolep otoolep self-assigned this Aug 21, 2015
@otoolep otoolep modified the milestones: 0.9.4, Longer term Aug 21, 2015
@otoolep
Copy link
Contributor

otoolep commented Aug 21, 2015

I too would like this, and it should be easy with some query re-writing of the AST. Let me see if I can get to it.

@beckettsean
Copy link
Contributor

A potentially easier workaround than multiple OR statements would be to use a regex. I think it should be faster, too. E.g.

SELECT * from mydb WHERE service =~ /aa|bb/

That said, supporting IN would be great, especially for greater congruence with SQL.

@srikara
Copy link

srikara commented Nov 6, 2015

+1

@pauldix pauldix modified the milestones: 0.10.0, 0.9.5 Dec 8, 2015
@jwilder jwilder removed this from the 0.10.0 milestone Feb 1, 2016
@jsternberg jsternberg added the area/influxql Issues related to InfluxQL query language label May 17, 2016
@ch33hau
Copy link
Contributor

ch33hau commented Aug 4, 2016

Hi Guys,

Is this feature request still valid? If it is valid, can I work on this task?

Thanks

@jsternberg
Copy link
Contributor

Yes, we are still interested in this feature.

@ch33hau
Copy link
Contributor

ch33hau commented Aug 18, 2016

Thanks, I will start working on this during weekend.

@rbetts rbetts added area/influxql Issues related to InfluxQL query language and removed help wanted area/queries labels Oct 27, 2017
@MariaCobretti
Copy link

I would love this feature

@innovationhub-asia
Copy link

+1

@xywendz
Copy link

xywendz commented Jan 4, 2018

this feature any update?

@maxp-edcast
Copy link

Looking forward to this. I would be fine using the WHERE .. OR or regex alternatives, but even won't work when the list of values passed to IN is very large (20k plus). Right now I don't see such a way to process this data without causing a "url too large" error.

@jsternberg
Copy link
Contributor

jsternberg commented Mar 1, 2018

So this issue isn't likely to be resolved very quickly, but I thought I should point out that we support using POST for queries and that you can put the query itself in the body. I think you can use application/x-www-form-urlencoded or you can use multipart/form-data. If you use the first, just urlencode the query. If you use the second, you can upload the query to a file with the query parameter q and then just insert the query into that.

Here's an example of doing it in Go with a GET/POST and application/x-www-form-urlencoded:

params := url.Values{}
params.Set("q", "your super long query")
body = strings.NewReader(params.Encode())

req, _ := http.NewRequest("GET", "http://localhost:8086/query", body)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
http.DefaultClient.Do(req)

Here's a (more complicated) example where you upload a file using POST. I'm honestly not sure if, practically, they are any different from each other.

var q io.Reader // this got defined at some point and is a really large query, maybe an *os.File?
body := bytes.NewBuffer(nil)
writer := multipart.NewWriter(body)

// Retrieve the filename if we are reading from a file.
// The server doesn't actually use this information, but it's nice to include anyway.
filename := "<stdin>"
if f, ok := q.(*os.File); ok {
	filename = filepath.Base(f.Name())
}

// Create the form file and copy the contents of the io.Reader into it.
f, err := writer.CreateFormFile("q", filename)
if err != nil {
	return nil, err
}
io.Copy(f, q)
writer.Close()

req, _ := http.NewRequest("POST", "http://localhost:8086/query", body)
req.Header.Set("Content-Type", writer.FormDataContentType())
http.DefaultClient.Do(req)

I hope that helps.

Note that you can mix query parameters and the body parameters so you can put things like db=testdb in the query while putting the query itself in the body.

@YEMEAC
Copy link

YEMEAC commented May 9, 2018

@kalidasya "We have another usecase, the support for IN would make it possible to integrate Grafana's multiselect feature with influx" here for this reason! i'm trying to use "all" option with a variable in Grafana but doesn't work, only if you select all them but one by one

@brian15co
Copy link

Is this a feature that is still being developed?

@walterdolce
Copy link

I just come across this issue as well while I was trying to show data aggregated by host (so same use case as the second comment before mine above). I believe many will benefit from this capability.

I am surprised it's not already implemented..

@atthom
Copy link

atthom commented Dec 4, 2018

It would be great to have this feature.

@dgnorton dgnorton added the 1.x label Jan 7, 2019
mark-rushakoff pushed a commit that referenced this issue Jan 11, 2019
* feat(view-token-overlay): add view token overlay

* test(tokens): update tests

* chore(auths): rename mock data file

* feat(token-view): clicking on description opens token view modal

* feat(token-view): add ability to close overlay

* feat(token-view): display token permissions with updated permissions shape

* feat(token-view): wip update authorization and permission shapes

* feat(auth): wip refactor auth permissions

* fix(auth): generate permissions via functions

* fix(auth): make Id ID

* chore(types): update generated client

* feat(auth): wip add user and org names to auth

* fix(user): didnt save rebase

* feat(auth): WIP refactor auth

* feat(auth): check for user existence during auth creation

* feat(auth): org must exist during auth creation

* fix(auth): pluralize telegrafs resource type

* docs(http): update swagger definition for the Authorization

* test(auth): fix broken tests

* docs(swagger): update cur_swagger Authrorizations

* fix(api): remove trace from cur_swag

* test(ui/token): update components with new generated type definitions

* feat(http): add lookup service adding names for permissions

* fix(http): remove debugging panics

* chore: go tidy

* fix: unsaved rebase

* test(idpe): add ids to Authorizations for log tests
@stale
Copy link

stale bot commented Jul 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 23, 2019
@stale
Copy link

stale bot commented Jul 30, 2019

This issue has been automatically closed because it has not had recent activity. Please reopen if this issue is still important to you. Thank you for your contributions.

@stale stale bot closed this as completed Jul 30, 2019
@douglasg14b
Copy link

Oh, good to see that influx is using this stalebot cancer.

Christ.

@Gp2mv3
Copy link

Gp2mv3 commented Oct 23, 2019

Is there something that we can do to have a IN clause or a workaround with regexes ?

@mjiderhamn
Copy link

mjiderhamn commented Oct 25, 2019

I think it would be great if someone could at least settle the discussion on the performance impact of using regexp vs OR. above @beckettsean "thinks" regexp should be faster, while here @cxreg has found support for his assumption that regexp "probably doesn't make use of the index", his link however being dead.

Docs also state that

queries with regular expressions are not as performant as those without

which is kind of obvious, but doesn't give any substantial guidance in this case.

So what's going on behind the scenes? Is the set of tags matching the regexp first being looked up and then used as a condition (should be fast for fairly sized sets), or is the tags of each entry matched against the regexp (potentially slooow) - or something completely different?

@CaptainMack
Copy link

+1 - using IN would be great in transitioning from Postgres to Influx

@atthom
Copy link

atthom commented Oct 28, 2019

@mjiderhamn this would be great but this issue beeing closed, I don't think there will be an update on this topic anytime soon.
I guess most of the effort of influxdata is devoted to influxdb 2.0. Unfortunately for us, there is no reason for them to change the syntax of a previous influxdb version.

@ishita07-danaher
Copy link

Hi..I was trying to implement something similar using both reg ex and 'OR' .
Where these approaches fail :

Reg ex : if the value I have passed is contained in the column value, it reads that though it shouldn't. Reg ex is similar to 'contains'..I want to compare the exact same value.

OR : I want data for both values not either of them.

Please suggest another approach for IN clause.

@jeanflorentine
Copy link

I think the all point of having an IN() clause is not write
select * from myDB where service in ('aa', 'bb');
which can be achieved (painfully) with OR
but to use sub query such as
select * from myDB where service in (select distinct(k8S_container_name) from K8S_E4));

This is real purpose of in() to deal with temporary on the fly intermediary collections, ain't it ?

@GerZah
Copy link

GerZah commented Dec 9, 2021

Reg ex is similar to 'contains'..I want to compare the exact same value.

If RegEx specifies an exact term, it is equivalent to checking for an exact value – as opposed to "contains" or "is similar to", which one would usually associate with RegEx.


Please look at this WHERE service = 'aa' OR service = 'bb' vs. this WHERE service =~ /aa|bb/

The latter is a RegEx that specifies two exact values, aa and bb, with the | meaning "alternative", or in other words OR. … This could also be WHERE service =~ /aa/ OR service =~ /bb/

However, the beauty in the | RegEx notation is to specify the multiple exact values in one (potentially long) =~ term, but without all the mucking around with OR.


… Still an IN(…) clause would be really awesome – +1 from me for that.

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

No branches or pull requests