I have this model
Note -> Keyword
where one note have multiple keywords that describe it. I have this Vertex:
As you can see in "Out Edges" it have 3 Noticia_keys.
If you go to graph you get this:
All ok. But if I run this query:
select #rid as rid, out(Noticia_keys).name as claves from #12:2
I get this output:
Where it that null come from?
New data:
Since I have clear the DB I have new records. This is a trace of one and the problem remains.
Both query suggested by Alessandro return nothing.
Michela: the Vertex are added through the library ODBOGM that translate Object to Vertex. It the binary API with addVertex and addEdge.
Well! Finally I found the error!!
What was wrong:
In the query
select #rid as rid, out(Noticia_keys).name as claves from #12:2
the out parameter has no quote. The query work fine if you type:
select #rid as rid, out("Noticia_keys").name as claves from #12:2
I found the error just running this query
that show me in the "claves" column, rid's of other vertex like Medios (#16:) and Fuentes (#17:). The real problem is that the query not fail if it not found a property on a vertex. Since I request "name", the Keyword vertex response correctly but the others out's return null.
Thank for your time!
Related
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.
Hello experts of the world. Need some help concerning executing a query with SpringData.
The expectation is to execute the Query below in the Spring Data annotation by combining with the repository method name (Automated Query Construction) to get a unique result. Apparently it fails from time to time by saying the result is not Unique.
The question here is if the method name is still considered in Query Construction while also executing the query in the annotation.
#Query("SELECT r from Revision r WHERE r.revisionBid = ?1 AND r.revisionStatusId = ?2 ORDER BY r.lastModifiedDate DESC")
Optional<Revision> findFirst(Integer revisionBid, Integer revisionStatusId);
Thanks in advance!
The query creation for limiting to 1 result is defined here with FIRST & TOP included in the method name.
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
I don't think "findFirst" will work when you're using an #Query, as the query will be constructed from HQL expression in the #Query rather than the fluent API passing over the method name. Because of this, when the query returns multiple results, it will throw the exception as the Optional is told to wrap a single returned object, not a collection. Add a LIMIT clause to the HQL query and you should be good.
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 just came across scenario when occasionally (not for all sets of data) I'm getting "Error: SQL0802 - Data conversion or data mapping error." exception when adding ORDER BY to simple query. For example, this works:
SELECT
market,
locationCode,
locationName
FROM locations
and the following is failing miserably:
SELECT
market,
locationCode,
locationName
FROM locations
ORDER BY locationName
I'm getting: Error: SQL0802 - Data conversion or data mapping error. (State:S1000, Native Code: FFFFFCDE)
I get the same error if I try to sort by name, or population, or anything really.... but only sometimes, meaning, when it errors on name or code, it would error if sorted by any field in locations subset. If it works for particular subset of locations, then it works for any sort order.
There are no null values in any of the fields, code and name fields are character fields.
Initially, I got this error when I added ROW_NUMBER column:
ROW_NUMBER() OVER(PARTITION BY market ORDER BY locationCode) as rowNumber
since, I narrowed it down to failing order case. I don't know which direction to go with it. Any thoughts?
update: there are no blank values for location name field. And even if I remove all fields in this subset and leave only 7 digit numeric id and sort by that field. I still get the same error.
WITH locs as (
SELECT id
FROM locations
)
SELECT *
FROM locs
ORDER BY id
I get this error when I SELECT DISTINCT any field from the subset too.
I had/have the exact same situation as described. The error seemed to be random, but would always appear when sorting was added. Although I can't precisely describe the technical details, what I think is occurring is the "randomness" was actually due to the size of the tables, and the size of the cached chunks of returned rows from the query.
The actual cause of the problem is junk values and/or blanks in the key fields used by the join. If there was no sorting, and the first batch of cached results didn't hit the records with the bad fields, the error wouldn't occur at first...but eventually always it did.
And the two things that ALWAYS drew out the error IMMEDIATELY were sorting or paging through the results. That's because in order to sort, it has to hit every one of the those key fields, and then cache the complete results. I think. Like I said, I don't know the complete technobabble, but I'm pretty sure that's close in laygeek terms.
I was able to solve the error by force-casting the key columns to integer. I changed the join from this...
FROM DAILYV INNER JOIN BXV ON DAILYV.DAITEM=BXV.BXPACK
...to this...
FROM DAILYV INNER JOIN BXV ON CAST(DAILYV.DAITEM AS INT)=CAST(BXV.BXPACK AS INT)
...and I didn't have to make any corrections to the tables. This is a database that's very old, very messy, and has lots of junk in it. Corrections have been made, but it's a work in progress.
there are a few topics about this already with accepted answers but I couldn't figure out a solution based on those:
Eg:
Ruby on Rails: must appear in the GROUP BY clause or be used in an aggregate function
GroupingError: ERROR: column must appear in the GROUP BY clause or be used in an aggregate function
PGError: ERROR: column "p.name" must appear in the GROUP BY clause or be used in an aggregate function
My query is:
Idea.unscoped.joins('inner join likes on ideas.id = likes.likeable_id').
select('likes.id, COUNT(*) AS like_count, ideas.id, ideas.title, ideas.intro, likeable_id').
group('likeable_id').
order('like_count DESC')
This is fine in development with sqlite but breaks on heroku with PostgreSQL.
The error is:
PG::GroupingError: ERROR: column "likes.id" must appear in the GROUP BY clause or be used in an aggregate function
If I put likes.id in my group by then the results make no sense. Tried to put group before select but doesn't help. I even tried to take the query into two parts. No joy. :(
Any suggestions appreciated. TIA!
I don't know why you want to select likes.id in the first place. I see that you basically want the like_count for each Idea; I don't see the point in selecting likes.id. Also, when you already have the ideas.id, I don't see why you would want to get the value of likes.likeable_id since they'll both be equal. :/
Anyway, the problem is since you're grouping by likeable_id (basically ideas.id), you can't "select" likes.id since they would be "lost" by the grouping.
I suppose SQLite is lax about this. I imagine it wouldn't group things properly.
ANYWAY(2) =>
Let me propose a cleaner solution.
# model
class Idea < ActiveRecord::Base
# to save you the effort of specifying the join-conditions
has_many :likes, foreign_key: :likeable_id
end
# in your code elsewhere
ideas = \
Idea.
joins(:likes).
group("ideas.id").
select("COUNT(likes.id) AS like_count, ideas.id, ideas.title, ideas.intro").
order("like_count DESC")
If you still want to get the IDs of likes for each item, then after the above, here's what you could do:
grouped_like_ids = \
Like.
select(:id, :likeable_id).
each_with_object({}) do |like, hash|
(hash[like.likeable_id] ||= []) << like.id
end
ideas.each do |idea|
# selected previously:
idea.like_count
idea.id
idea.title
idea.intro
# from the hash
like_ids = grouped_like_ids[idea.id] || []
end
Other readers: I'd be very interested in a "clean" one-query non-sub-query solution. Let me know in the comments if you leave a response. Thanks.