On 07/10/2016 01:32 PM, R.I.Pienaar wrote:
> hey,
>
> Been playing with the PQL language and it's quite nice, have 2 questions.
>
> I want to do a regex case insensitive match, docs mention you can do whatever
> Postgres supports but I can't figure out how to do case insensitive matches
> with PQL?
>
> Postgres supports ~ and ~* operators but PQL only supports ~. So I suppose
> I could match [aA][bB][cC] to get case insensitivity, but thats a tad ugly
Hey R.I,
I agree -- the docs are incorrect here and if you link the page you're
looking at I'll change them. PuppetDB currently only supports postgres's
~ operator, but I think adding support for ~* would be a good feature
and technically easy, so I've created
https://tickets.puppetlabs.com/browse/PDB-2861 to address it. For now
your hack is probably the best you can do.
>
> Next I have a fact like:
>
> foo => { bar => ["a", "b", "c"]}
>
> How do I search into that where bar contains "b"? There's an "in" operator
> but I can't seem figure out both how to search inside the sub hash and also
> how to match inside a array like that?
Querying structured facts in PQL is still pretty inconvenient in some
cases, but you could do this with something like
fact_contents{path ~> ["foo", "bar", "\\d"] and value = "b"}
This can be inserted as a subquery to get the certnames associated with
such a value, e.g
nodes{certname in fact_contents[certname]{path ~> ["foo", "bar", "\\d"]
and value = "b"}}
Incidentally, we have two tickets in flight (PDB-2632 and PDB-2633) that
will enable the nicer syntax
inventory{facts.foo.bar.match("\\d") = "b"}
to do the same thing (subject to tweaking still but that's the gist of
it). These should be included in the next feature release, assuming no
issues pop up. Having some kind of explicit handling for array
containment seems like an interesting idea -- we'll have to give it some
thought.
Wyatt
>
> ---
> R.I.Pienaar
>