I'm using orientdb version: 2.1.8
The following query fails with a parsing exception:
select from some_vertex where in('<edge_name>').id not contains "1"
Error:
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #0: Error parsing query: select from room where in('inroom').id not contains "1" Encountered "" at line 1, column 24.
Was expecting one of:
Thanks.
if you want to exclude a determinate value you can use 'NOT IN' syntax. In your case the query would be like this:
select from Room where in('inRoom').id not in '1'
I tried the query with a structure Furniture --inRoom-> Room and it returns all of the Room vertex not connected with the Furniture.id 1
Related
Using Amazon Athena, I am working with a set of data stored as variable characters and would like to convert them to dates. There are two columns within a table that have dates: (1) action_date and (2) pricing_date.
With action_date, I have been able to successfully convert the original data using the dateparse function with the following query:
SELECT date_parse(s.action_date,'%m/%d/%Y %H:%i:%s') AS dataconverted
FROM "database"."sales" s
With pricing_date, I am having difficulties doing the same despite the data being in the same format. I would assume that the query should be the same. Following is my query:
SELECT date_parse(s.pricing_date,'%m/%d/%Y %H:%i:%s') AS dataconverted
FROM "mydatabase"."sales" s
Following is the error I get in Amazon Athena:
Your query has the following error(s):
[ErrorCategory:USER_ERROR, ErrorCode:INVALID_ARGUMENT], Detail:INVALID_FUNCTION_ARGUMENT: Invalid format: ""
This query ran against the "mydatabase" database, unless qualified by the query.
How I can convert the successfully convert the variable character text into a date format? What could I possibly be missing?
From the error it looks like the pricing_date column sometimes is an empty string. date_parse will throw an error if the input is not on the specified formatat. You can observe this by running SELECT date_parse('', '%m/%d/%Y %H:%i:%s') or SELECT date_parse('asdasd','%m/%d/%Y %H:%i:%s').
You can work around this by adding a guard (e.g. IF(s.pricing_date <> '', date_parse(…), NULL)) or by wrapping the call in TRY, which results in NULL if there was an error:
SELECT try(date_parse(s.pricing_date,'%m/%d/%Y %H:%i:%s')) AS dataconverted
FROM "mydatabase"."sales" s
I have a field with JSON files like this:
"{\"names\":[\"James\",\"Bob\",\"Kate\",\"Tim\",\"Jerald\",\"Massimo\",\"Drake\",\"Ellen\"],\"country\":[\"Usa\",\"Montenegro\",\"Turkey\",\"Spain\"]}"
I want to get only those rows where this field in the country includes 'USA'.
So I tried to write smth like this:
select *
from table
where json_field :: jsonb #> '{"country":"USA"}'::jsonb == True
However, my interpreter states that
message [ERROR: type "jsonb" does not exist]
Maybe there is another way how to check for the value in postgres?
Also tried this
json_field->'country' #> '"USA"'
But this returns this
message [ERROR: operator does not exist: json #> unknown
this is my first question ever in StackOverflow and as suggested, I have looked at other similar questions and attempted to use their responses for my problem. So far, no luck.
The situation is as follows:
I have a custom query in JPA.
#Query(value="SELECT u.str_id,u.str_exercise_name, u.str_target_body_part,u.char_effect FROM training_schema.exercise_entity u WHERE u.str_exercise_name = ?1 and u.str_target_body_part= ?2", nativeQuery=true)
ExerciseEntity findExerciseEntityByNameAndTargetBodyPart(String str_exercise_name,String str_target_body_part);
If I remove the name of the columns (u.str_id, u.str_exercise_name, u.str_target_body_part, u.char_effect) and replace the query with:
#Query(value="SELECT u FROM training_schema.exercise_entity u WHERE u.str_exercise_name = ?1 and u.str_target_body_part= ?2", nativeQuery=true)
ExerciseEntity findExerciseEntityByNameAndTargetBodyPart(String str_exercise_name,String str_target_body_part);
I get the following error:
"The column name str_id was not found in this ResultSet"
The fact that the error doesn't come when I mention all the columns and is generated when I use alias 'u' doesn't make sense because this would mean that if I ever had to work with a larger table with, say, 10 columns, I would have to write them all out.
One more piece of information that hopefully helps: With the version of the query where I am using 'u' instead of the column names, the error is ONLY generated when a matching record is found. For a null return from the database, there is no problem.
Using Java Spring and PostgresSQL.
I was able to figure out the problem.
In the query where I am using the alias 'u' ALONE, I had to make a slight change. Instead of just saying 'u', I changed it to:
#Query(value="SELECT u.* FROM training_schema.exercise_entity u WHERE u.str_exercise_name = ?1 and u.str_target_body_part= ?2", nativeQuery=true)
ExerciseEntity findExerciseEntityByNameAndTargetBodyPart(String str_exercise_name,String str_target_body_part);
Using only 'u', was returning a record set WITHOUT any headers. Adding the '*' caused the query to return a resultset with column names which made the error go away.
Trying this query in Grateful dead database provided in orientdb gives 146 records:
select expand(in('sung_by')) from V where name = 'Garcia'
But when we try the similar version of below query: select expand(in(sung_by)) from V where name = 'Garcia', 150 records are returned
Is it a bug?? Just trying orientdb from past week, followed tutorial from this website and this was second issue found.
By using select expand(in(sung_by)), the value of the field sung_by is resolved at query execution, but there is no field called sung_by, so it's null.
For this reason, it's like executing select expand(in()) in that case. By using 'sung_by', instead, only the edges with label sung_by will be traversed.
So, put always " or ' around edge's class/label to traverse.
I am getting this error running an insert query for a single record:
DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null,
DRIVER=3.62.56
Exception: org.springframework.dao.DataIntegrityViolationException
I looked this up on IBM's help site, but there being no parameter index, I am stuck. The SQL state also seems to specify it is other than a value being too big.
The format of the query is INSERT INTO [[TABLE_NAME]] VALUES (?,?,?,...) using Spring's JdbcTemplate.update(String sql, Object... params).
This being for work, I cannot post schema nor query. I am looking for general advice into debugging this issue. I already know using Arrays.toString(Object[]) does not print out in SQL format.
To find the explanation for SQLCODE -302 in the manual you need to search for SQL0302N (the general rule for DB2 SQLCODE values is this: "SQL" plus four digits, padded if necessary with zeros on the left, plus "N" for "negative" because -302 is a negative number).
If you have the DB2 command line processor installed, you can also use it to look up error codes:
db2 ? sql302
which would produce something like this:
SQL0302N The value of a host variable in the EXECUTE or OPEN
statement
is out of range for its corresponding use.
Explanation:
The value of an input host variable was found to be out of range for
its use in the SELECT, VALUES, or prepared statement.
In other words, one of the bind variables in your INSERT is too large for the target column. You'll need to compare the table column definitions with the actual values you're trying to insert.
In addition to mustaccio's answer you can also get the info from sql with SYSPROC.SQLERRM. Example:
values SYSPROC.SQLERRM ('SQL302', '', '', 'en_US', 0)
SQL0302N The value of a host variable in the EXECUTE or OPEN statement
is out of range for its corresponding use.
Explanation:
...