how update in sparql - sparql

In my n3 data in rdf, i have the following data, and i want to change a little bit.
I have the value 'no' and i want to change that value to 'yes'
house:a1 a stand:Map;
house:id "1"^^xsd:integer;
house:sell "no";
I want to select that value 'sell? and change then, that is why i do the select
select ?sell where {
?s stand:sell ?sell.
i want to delete tha value "no" and change to "yes" but i dont know how to do it, but i dont know how to do it.

Related

Dynamic where condition PostgreSQL

I am building a CRUD application that allows the user to input some search criteria and get the documents corresponding to those criteria. Unfortunately i have some difficulties in creating a query in postgres that uses different conditions in the where part, based on the input sent by the user.
For example if the user set as search criteria only the document number the query would be defined like this:
select * from document where document_num = "value1"
On the other hand if the user gave two criteria the query would be set up like this:
select * from document where document_num = "value1" and reg_date = "value2"
How can i set up a query that is valid for all the cases? Looking in other threads i saw as a possible solution using coalesce in the where part:
document_num = coalesce("value1", document_num)
The problem with this approach is that when no value is provided postgres converts the condition to document_num IS NOT NULL which is not what i need (my goal is to set the condition to always true).
Thanks in advance
So the solution by #D-shih will work if you have a default value and you can also use COALESCE as below.
SELECT *
FROM document
WHERE document_num = COALESCE("value1", default_value)
AND reg_date = COALESCE("value2", default_value);
If you don't have default values then you can create your query using CASE WHEN(here I am supposing you have some variables from which you will determine which conditions to apply like when to apply document_num or when to apply reg_date or when to apply both). Giving a little example below.
SELECT *
FROM document
WHERE
(
CASE
WHEN "value1" IS NOT NULL THEN document_num = "value1"
ELSE TRUE
END
)
AND (
CASE
WHEN "value2" IS NOT NULL THEN reg_date = "value2"
ELSE TRUE
END
)
You can read more how to use CASE WHEN here.
If I understand correctly, you can try to pass the user input value by parameter.
parameter default value might design that the user can't pass if the user didn't want to use the parameter it will use the default value.
we can use OR to judge whether use parameter otherwise ignores that.
SELECT *
FROM document
WHERE (document_num = :value1 OR :value1 = [default value])
AND (reg_date = :value2 OR :value2 = [default value])

find diffrences between 2 tables sql and how can i get the changed value?

i have this query
insert into changes (id_registro)
select d2.id_registro
from daily2 d2
where exists (
select 1
from daily d1
where
d1.id_registro = d2.id_registro
and (d2.origen, d2.sector, d2.entidad_um, d2.sexo, d2.entidad_nac, d2.entidad_res,
d2.municipio_res, d2.tipo_paciente,d2.fecha_ingreso, d2.fecha_sintomas,
d2.fecha_def, d2.intubado, d2.neumonia, d2.edad, d2.nacionalidad, d2.embarazo,
d2.habla_lengua_indig, d2.diabetes, d2.epoc, d2.asma, d2.inmusupr, d2.hipertension,
d2.otra_com, d2.cardiovascular, d2.obesidad,
d2.renal_cronica, d2.tabaquismo, d2.otro_caso, d2.resultado, d2.migrante,
d2.pais_nacionalidad, d2.pais_origen, d2.uci )
<>
(d1.origen, d1.sector, d1.entidad_um, d1.sexo, d1.entidad_nac, d1.entidad_res,
d1.municipio_res, d1.tipo_paciente, d1.fecha_ingreso, d1.fecha_sintomas,
d1.fecha_def, d1.intubado, d1.neumonia, d1.edad, d1.nacionalidad, d1.embarazo,
d1.habla_lengua_indig, d1.diabetes, d1.epoc, d1.asma, d1.inmusupr, d1.hipertension,
d1.otra_com, d1.cardiovascular, d1.obesidad,
d1.renal_cronica, d1.tabaquismo, d1.otro_caso, d1.resultado, d1.migrante,
d1.pais_nacionalidad, d1.pais_origen, d1.uci ))
it results in an insersion data that doesn't exist in another table, that's fine. but i want know exactly which field has changed to store it in a log table
You don't mention precisely what you expect to see in your output but basically to accomplish what you're after you'll need a long sequence of CASE clauses, one for each column
e.g. one approach might be to create a comma-separated list of the column names that have changed:
INSERT INTO changes (id_registro, column_diffs)
SELECT d2.id_registro,
CONCAT(
CASE WHEN d1.origen <> d2.origen THEN 'Origen,' ELSE '' END,
CASE WHEN d1.sector <> d2.sector THEN 'Sector,' ELSE '' END,
etc.
Within the THEN part of the CASE you can build whatever detail you want to show
e.g. a string showing before and after values of the columns CONCAT('Origen: Was==> ', d1.origen, ' Now==>', d2.origen). Presumably though you'll also need to record the times of these changes if there can be multiple updates to the same record throughout the day.
Essentially you'll need to decide what information you want to show in your logfile, but based on your example query you should have all the information you need.

SPARQL: filter on both string and integer?

I'm testing SPARQL with Protégé on this data file
https://raw.githubusercontent.com/miranda-zhang/cloud-computing-schema/master/example/sparql-generate/result/gcloud_vm.ttl
Validated the following works:
PREFIX cocoon: <https://raw.githubusercontent.com/miranda-zhang/cloud-computing-schema/master/ontology_dev/cocoon.ttl>
SELECT ?VM ?cores
WHERE {
?VM a cocoon:VM ;
cocoon:numberOfCores ?cores .
}
For example, it returns something like:
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-ULTRAMEM-80-PREEMPTIBLE "80"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-64-PREEMPTIBLE "64"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-2 "2"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-F1-MICRO "shared"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-8-PREEMPTIBLE "8"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-32 "32"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-16-PREEMPTIBLE "16"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-96-PREEMPTIBLE "96"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-4 "4"#
I'm not sure if I can apply a filter on ?cores, I tried the following, but they returned nothing:
cocoon:numberOfCores "shared" .
Or
FILTER(?cores = "4") .
I'd also like to apply filter on ?cores (i.e. > 4 and < 8), so I have to make it an xsd:integer? But then I have to get rid of shared which is about < 1 core
Thanks AKSW, impressive knowledge about Protégé.
In the end, I changed my data type to xsd:decimal. Seems to be enough for now.

Crystal reports - How to translate a group by with condition into a report

I have the following query
SELECT dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
FROM [1-CR-liste_Pixi] LEFT JOIN dbo_DIRIGEANTS ON [1-CR-liste_Pixi].Siren = dbo_DIRIGEANTS.SIREN
GROUP BY
dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
HAVING
((([1-CR-liste_Pixi].Siren) Not Like "p*")
AND (([1-CR-liste_Pixi].Nic) Not Like "p*")
AND ((dbo_DIRIGEANTS.REP_LEGAL)="1") AND (([1-CR-liste_Pixi].Nicsiège) Not Like "p*"))
ORDER BY IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1));
What I'm interested is setting that part
GROUP BY dbo_DIRIGEANTS.IU_DIR,
[1-CR-liste_Pixi].Siren,
[1-CR-liste_Pixi].Nic,
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
And especially that part
IIf([QUAL_JUR]>"0003","",Right([QUAL_JUR],1))
Because of performance, I kept my tables and use CR's functions to deal with the condition part instead of creating a query.
I did the following:
Went to Formula selection and choose group
Chose the field I wanted
Put the formula
The error below popped out
It said my formula needs to be using boolean values.
To see if I was right, I've amended it that way IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN TRUE ELSE FALSE. It worked.
TL;DR
Why I cannot do that in my expert group selection?
IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN "" ELSE RIGHT({QUAL_JUR},1)
Thanks
Group selection should return Boolean but that doesn't mean you write true or false....it means you pass some thing to fields to perform job
IF {DIRIGEANTS.QUAL_JUR} > "0003"
THEN datasefield=""
ELSE database fled=RIGHT({QUAL_JUR},1)
This will do the job
Edit: Apologize as conditions are a bit confused for your requirement
Create formula and write below code
IF {DIRIGEANTS.QUAL_JUR} > "0003" THEN ""
ELSE RIGHT({DIRIGEANTS.QUAL_JUR},1)
Now go to insert group and select this formula and click ok. This will do the trick

Oracle: updating column IF ONLY it is not in condition of Merge statement

I'm having trouble with this Oracle Merge query.
merge into NEW_DOCTORS NP
USING OLD_DOCTORS MD
on (MD.SSN=NP.SSN OR MD.NPI=NP.NPI OR MD.PIN=NP.PIN)
WHEN MATCHED THEN
UPDATE SET
NP.othervalues=MD.othervalues
NP.PIN/SSN/NPI=MD.PIN/SSN/NPI (**update two of these three that did not return TRUE in the above ON condition)
WHEN NOT MATCHED THEN
insert(NP.SSN,NP.NPI,NP.PIN,NP.other_values)
values(MD.SSN,MD.NPI,MD.PIN,MD.other_values)
Is this possible? Thanks!
EDIT: I'm asking because I read somewhere that fields that are in the ON condition can't be updated. However I'm not sure if the author was talking only in context of the field that evaluates true or for all fields. I'm hoping there's someone who might have an idea about this, as well as any workarounds.
You can use CASE WHEN ... :
UPDATE SET
NP.othervalues=MD.othervalues
,NP.PIN = CASE WHEN (MD.SSN=NP.SSN OR MD.NPI=NP.NPI) THEN MD.PIN ELSE NP.PIN END
,--add here the 2 others
This means, when you have MD.SSN=NP.SSN OR MD.NPI=NP.NPI true, then update NP.PIN with MD.PIN else let the same value NP.PIN
Or you can do 3 differents MERGE, so it will be more readable.
EDIT
Thinking about it, if you update only when this is not the same value (cause it will join only on same value) you can directly update them with the MD table value.
Do that :
NP.othervalues=MD.othervalues
,NP.PIN=MD.PIN
,NP.SSN=MD.SSN
,NP.NPI=MD.NPI
If they match, the update will keep same value, if not it will update the value.