How to get data between start date and enddate - hql

This is the query:
" select dbo from EmpWorkDiaryEntriesDBO dbo"
+ "lef join fetch dbo.empWorkDiaryEntriesDetailsDBOSet dbos"
+ "where dbo.recordStatus='A' and dbo.erpWorkEntryDate between (:startDate)
and (:endDate) order by erpWorkEntryDate ASC ";
And this is the error
getting eror expecting EOF, found ')'

Related

org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record

#Query(value = "SELECT DISTINCT * " +
"FROM chores WHERE id in (SELECT a.id " +
"FROM chores as a INNER JOIN chores_assign_users as b ON a.id=b.chore_id " +
"WHERE (a.is_deleted=FALSE " +
"AND a.family_id=:familyId " +
"AND (:userId IS NULL OR (cast(b.user_id as VARCHAR) IN :userId)) " +
"AND (:status IS NULL OR (a.status IN :status)) " +
"AND (:title IS NULL OR a.title LIKE cast(:title as text)) " +
"AND (:from IS NULL OR :to IS NULL OR cast(created_at as VARCHAR) >= :from AND cast(created_at as VARCHAR) <= :to)) " +
"ORDER BY :sortByDeadline" +
", CASE WHEN :sortByDeadline THEN a.deadline END DESC " +
", CASE WHEN NOT :sortByDeadline THEN a.created_at END DESC)",
countQuery = "SELECT COUNT(DISTINCT a.id) FROM chores as a INNER JOIN chores_assign_users as b ON a.id=b.chore_id " +
"WHERE a.is_deleted=FALSE " +
"AND a.family_id=:familyId " +
"AND (:userId IS NULL OR (cast(b.user_id as VARCHAR) IN (:userId))) " +
"AND (:status IS NULL OR (a.status IN (:status))) " +
"AND (:title IS NULL OR a.title LIKE cast(:title as text))" +
"AND (:from IS NULL OR :to IS NULL OR cast(created_at as VARCHAR) >= :from AND cast(created_at as VARCHAR) <= :to)) ",
nativeQuery = true)
ArrayList<Chore> findAlLFilteredByUserAndStatusAndTitleSortedByCreatedAtOrDeadLine(#Param("familyId") int familyId,
#Param("userId") List<String> userId,
#Param("status") List<String> status,
#Param("title") String title,
#Param("sortByDeadline") boolean sortByDeadline,
#Param("from") String from,
#Param("to") String to,
Pageable pageable);
I have this native query in a jpa repository. As you can see, I search for the records which have user_id IN :userId. This works fine as long as userId contains only one element. But if userId contains more than one element, this exception will be thrown org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record. The same problem happens to "AND (:status IS NULL OR (a.status IN :status)) "
user_id has type integer
status has type varchar
I am having a hard time finding a way to fix this. Could you please help me with this? And also, is it good to pass a List of integers to the query as a list of string by converting every elements to string just like I do with userId in this case? Can it be the problem and how can I fix it? Thank you for your time!
org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record. The same problem happens to "AND (:status IS NULL OR (a.status IN :status)) "
I think using COALESCE(:status) IS NULL instead of :status IS NULL will solve above problem.

Error missing ')' at Oracle NoSQL table creating table

I have the following error when trying to create this table
java.lang.IllegalArgumentException: Error: at (1, 1140) missing ')' at
',', at line 1:1140
"create table if not exists " + TABLE_NAME +
"(id string, " +
"subId string, " +
"startTime timestamp(4), " +
"timeId string, " +
"primary key(id, shard(subId, startTime)))";
Any ideas in how to solve this
The error message is not clear but your issue is because the shard(...) should be the first thing after primary key (, and , id should come after the shard key.
"create table if not exists " + TABLE_NAME +
"(id string, " +
"subId string, " +
"startTime timestamp(4), " +
"timeId string, " +
"primary key(shard(subId, startTime), id))";

How to insert into a snowflake variant field using a DAO?

I have the following code:
#RegisterMapper(MyEntity.ResultMapper.class)
#UseStringTemplate3StatementLocator
public interface MyDao {
#Transaction(TransactionIsolationLevel.SERIALIZABLE)
#SqlBatch("INSERT INTO mySchema.myTable (" +
" id, entity_type, entity_id, flags " +
" ) VALUES " +
"(" +
" :stepId , :entityType , :entityId,parse_json(:flags) " +
")")
#BatchChunkSize(500)
Object create( #BindBean List<MyEntity> entities );
}
As you can see, I am bulk inserting a list of entities into my Snowflake table using this DAO.
The issue is that I am unable to insert into the flags columns, which is a variant. I have tried to_variant(:flags) and currently parse_json(:flags), but the JDBI keeps throwing the following error:
net.snowflake.client.jdbc.SnowflakeSQLException: SQL
compilation error:
Invalid expression [PARSE_JSON(?)] in VALUES clause
[statement:"INSERT INTO mySchema.myTable ( id, entity_type,
entity_id, flags ) VALUES ( :stepId , :entityType , :entityId,
parse_json(:flags) )", located:"null", rewritten:"null",
arguments:{ positional:{}, named:{timeStamp:'null',
entityType:MYENTITY,
flags:'{"client":"myClient","flow":"myFlow"}',stepId:null,
entityId:'189643357241513', class:class myOrg.MyEntity}, finder:[]}]
How should I pass the value in the flags column ? Has anyone attempted this before? The flags field in MyEntity is in my control, I can keep it as a POJO or a String, whichever helps me resolve this issue.
See the comment by Jiansheng Huang for answer:
INSERT INTO T SELECT parse_json(:flag);

SpringJDBC Gives ORA-00933: SQL command not properly ended But Query Runs OK in DB Client

The following Oracle query runs OK in my DB Client, PL/SQL Developer, and returns 1 result.
On running it via NamedParameterJdbcTemplate (SpringJDBC) in my Java app, I get
java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
There can't be any space issues or anything obvious, because this exact query completes in PL/SQL.
private static final String SELECT1 =
" SELECT COUNT(*) "
" FROM table1 t1, table2 t2 " +
" WHERE t1.received_date > TRUNC(sysdate - 1) " +
" AND t1.received_date < TRUNC(sysdate) " +
" AND t1.type IN ('TYPE1', 'TYPE2') " +
" AND t2.received_num = t1.received_num; ";
public int getSelect1() {
HashMap<String,Object> paramMap = new HashMap<String,Object>();
return jdbcTemplate.queryForObject(SELECT1, paramMap, Integer.class);
}
I think you don't require the semi colon with the sql string.
private static final String SELECT1 =
" SELECT COUNT(*) " +
" FROM table1 t1, table2 t2 " +
" WHERE t1.received_date > TRUNC(sysdate - 1) " +
" AND t1.received_date < TRUNC(sysdate) " +
" AND t1.type IN ('TYPE1', 'TYPE2') " +
" AND t2.received_num = t1.received_num ";

simple join syntax not properly working

I'd like to show the number of records in the history table grouped by name of service
service(code,name)
history(id, code,....)
Please note that there is no relationship between the two table history and service, history stores the activity independently from the other tables
I have tested this sql query and it returns the expected result:
select s.name, count(*) from history c
join service s
on c.code=s.code
where c.state='INITIALE'
group by s.name
Actually, I'd like to write it in jpql, I did alike
Query query =entityManager.createQuery(" select s.name, count(*) from ServiceEntity s join"
+ " HistoryEntity c "
+ " where c.code=s.code and c.state='INITIALE'"
+ " group by c.name order by c.name"
);
I got this error : Path expected for join!....
Invalid path: 'c.code'....right-hand operand of a binary operator was null....unexpected end of subtree
Try this
Query query = entityManager.createQuery("select s.name, count(s) from ServiceEntity s, HistoryEntity c "
+ " where c.code = s.code and c.state = 'INITIALE'"
+ " group by s.name order by s.name"
);

Resources