How can I use / in select sparql select ?first/object, I what name of column in result to be first/object
You cannot. '/' is not a legal character in a SPARQL variable name.
As #UninformedUser mentioned in their comment, you can see the full range of legal variable names by looking at the SPARQL grammar: https://www.w3.org/TR/sparql11-query/#rVARNAME .
Related
I want to use special characters in BigQuery columns but when using it it is throwing error as : Syntax error: Expected end of input but got "/" at [2:16].
Query :
SELECT *,
buget as budget/bin
FROM `dummy.book1`
Thanks
I don't think that's possible. BQ has column name naming rules so even when you do SELECT x AS y, y still has to follow those rules
trying found out relation name in public schema that contain string "main" and "parted".
So far I have tried.
\dt public.(*main* | *parted*)
-- ERROR: invalid regular expression: parentheses () not balanced
I also tried the following queries:
SELECT
regexp_match('parted1 new main', '(main|parted\S+)');
SELECT
regexp_matches('main new parted1', '(main|parted\S+)');
SELECT
regexp_substr ('main new parted1', '(main|parted\S+)');
SELECT
regexp_substr ('main new parted1', '(main|parted\S+)');
I expect a pattern that will match substring that have pattern "main" or "parted\S+".
In psql manual:
All regular expression special characters work as specified in Section
9.7.3, except for . which is taken as a separator as mentioned above, * which is translated to the regular-expression notation .*, ? which is translated to ., and $ which is matched literally.
From the quote so it's doable?
as the title says, please find the block of codes that worked and didn't work respectively.
select *
from public.transactions
where id in ('ABCDE-3131243553O2')
The query above didn't work but the one below did.
select *
from public.transactions
where id ~* 'ABCDE-3131243553O2'
Does anyone know any particular reason why? I have been googling but to no avail. Thanks in advance!
These are not equivalent at all. Consider:
where id ~* 'ABCDE-3131243553O2'
This matches any string that contains the expression. For instance this returns both rows.
select *
from (values ('ABCDE-3131243553O2'), ('blahblahblahABCDE-3131243553O2foofoofoo')) v(id)
where id ~* 'ABCDE-3131243553O2';
The equivalent regular expression for = or in is:
where id ~* '^ABCDE-3131243553O2$'
This anchors the pattern, so no other characters are allowed.
If you are not getting a match using in when you are expecting one, then a likely cause are hidden characters in the data (or perhaps the comparison value). The most common "hidden" characters are spaces at the beginning or end. Another issue could be look-alike characters. Is the 1 really a 1 or a lower case L?
I am trying to write a query to check if an element is within an array of Strings.
Here is my simple select query along with the output
select languages from person limit 3;
{CSS,HTML,Java,JavaScript,Python}
{JavaScript,Python,TensorFlow}
{C++,Python}
How do I write a query to find all people who have "Java" as a listed language they know?
I tried following the syntax but it isn't working.
select languages from person where languages #> ARRAY['Java']::varchar[];
You need to use a string constant on the left side, and the ANY operator on the array column:
select languages
from person
where 'Java' = any(languages);
This assumes languages is defined as text[] or varchar[] as your sample output indicates
try this
select languages from person where 'Java' = ANY (string_to_array(languages , ','))
You can search for more than one pattern replacing '=' operator by the regular expression match operator '~' preceding by a POSIX regular expression, such as:
select languages from person where '[Java,Php]' ~ ANY (string_to_array(languages , ','))
what is difference between these two sql statements
1- select * from tblperson where name not like '[^AKG]%';
2- select * from tblperson where name like '[AKG]%';
showing same results: letter starting from a,k,g
like '[^AKG]% -- This gets you rows where the first character of name is not A,K or G. ^ matches any single character not in the specified set or a specified range of characters. There is one more negation not. So when you say name not like '[^AKG]%' you get rows where the first character of name is A,K or G.
name like '[AKG]% -- you get rows where the first character of name is A,K or G.
The wildcard character [] matches any character in a specified range or a set of characters. In your case it is a set of characters.
So both the conditions are equivalent.
You are using a double 'NOT'. The carrot '^' in your first character match is shorthand for 'not', so you are evaluating 'not like [not' AKG]% IE not like '[^AKG]%'.
1)In the first query you are using 'Not' and '^' basically it is Not twice so it cancels outs
therefore your query is 'Not Like [^AKG]' ==> 'Like [AKG]'
^ a.k.a caret or up arrow.
The purpose of this symbol is to provide a match for any characters not listed within the brackets [] , meaning that normally it wouldn't provide a result for anything that starts with AKG, but since you added the word NOT to the query , you are basically cancelling the operator, just as if you were doing in math :
(- 1) * (- 1)