-1

I want to insert literal which has brackets(") inside using insert statement.

sparql insert data { pred:a pred:b "Literal"}

The above query works fine.

sparql insert data { pred:a pred:b "\"Literal\""}

I want to add Literal along with quotes surrounding it. But the above query fails.

How to insert the literal along with quotes?

harish chava
  • 252
  • 2
  • 19
  • 1
    your first query can't work, it has to start with `INSERT DATA` - and doing `insert data { pred:a pred:b "\"Literal\""}` works fine for me. Looks more like your API is using non-standard SPARQL – UninformedUser Jun 22 '20 at 13:51
  • 1
    If this is in a programming language, you proabably need `\\` to get a single `\` into the string. – AndyS Jun 22 '20 at 14:50
  • @UninformedUser, In the code, I have been using insert data only. I am using the eclipse-RD4J console and connected to AWS Neptune for executing the commands. – harish chava Jun 23 '20 at 04:10
  • 1
    well, it would be good if you mention things like this in your question ... moreover, first you tagged your question with `rrd4j` now you are talking about `RD4J` - it is called `RDF4J` - please be more precise. It is **not** helpful if you do not **exactly** describe in your question what you're doing. – UninformedUser Jun 23 '20 at 05:38
  • now the question, **which error exactly** do you get? Did you try to double escape? OR do what Andy suggested? – UninformedUser Jun 23 '20 at 05:38

1 Answers1

1

The RDF4J Console has some known peculiarities in its handling of string escapes in SPARQL queries. A fix in this case is to use double escaping:

 insert data { pred:a pred:b "\\"Literal\\""}

Alternatively, you can also make use of single quotes instead of double quotes:

 insert data { pred:a pred:b '"Literal"'}
Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • **sparql insert data { pred:a pred:b "\"Literal\""}**, The above query works when I run the same query from the file(using sparql INFILE=""). But not working when running the query directly in the eclipse-RDF4J console. – harish chava Jun 29 '20 at 07:01