Ivo Velitchkov
Ivo Velitchkov

Reputation: 2431

Making SPARQL FILTER conditional

How to make a FILTER() conditional? This is the relevant part of my query:

SELECT *

WHERE {

 VALUES (?open) {$U2}
 ?URI_OPP CSV:id_opportunita ?ID_OPP.

 OPTIONAL { ?URI_OPP CSV:data_scadenza ?DATA_S }

 FILTER ((NOW() - xsd:datetime(?DATA_S)) > 0) 
}

It gets $U2 as a value for ?open. I want to apply the filter if ?open = 1, and not to apply it in all other cases.

While IF() works on the query results, I don't know what to use to switch off parts of the query itself.

Upvotes: 1

Views: 1153

Answers (1)

T3db0t
T3db0t

Reputation: 3551

Since the above commented never answered, I will:

FILTER(
  (?open != 1) ||
  ((NOW() - xsd:datetime(?DATA_S)) > 0)
)

Upvotes: 1

Related Questions