How to add condition ORDER BY in Confluence CQL? - confluence

We are trying to sort this CQL by the created parameter as per below CQL.
type=page and created >= startOfMonth("-90d")
Referred to the docs, but got the error when compiling
Could not parse cql
CQLs that had been tried
type=page AND created >= startOfMonth("-90d") AND order by created
type=page AND created >= startOfMonth("-90d") asc
type=page order by created AND created >= startOfMonth("-90d")
(type=page order by created) AND (created >= startOfMonth("-90d")).
Any pointers we missed or we should look at?
Appreciate your response in advance!

ORDER BY should be the last part of your JQL/CQL and does not require the inclusion of AND.
This CQL is untested, however I believe it should work: type=page AND created >= startOfMonth("-90d") ORDER BY created
See docs here: https://developer.atlassian.com/cloud/confluence/advanced-searching-using-cql/#order-by

Related

Converting SQL query with FORMAT command to use in entity framework core

I have an SQL query:
SELECT
FORMAT(datetime_scrapped, 'MMMM-yy') [date],
count(FORMAT(datetime_scrapped, 'MMMM-yy')) as quantity
FROM scrap_log
GROUP BY FORMAT(datetime_scrapped, 'MMMM-yy')
It basically summarises all the entries in the scrap_log table by month/year and counts how many entries are in each month/year. Returns two columns (date and quantity). But I need to execute this in an ASP.NET core API using Entity Framework core. I tried using .fromSqlRaw(), but this expects all columns to be returned and so doesn't work.
I can find plenty of info on EF to implement group by and count etc... But I cannot find anything for the FORMAT(datetime, "MMMM-yy") part. Please could somebody explain to me how to do this?
EDIT: Seems already I appear to be going about this the wrong way in terms of efficiency. I will look into alternative solutions based on comments already made. Thanks for the fast response.

Query annotation not working for max(id)

I have a domain object GenJournal and it has an "id" member (Long) that's auto-generated. I also have a JPA repository that I've added ...
#Query("select coalesce(max(u.id), 0) from GenJournal u")
Long getMaxId();
The method getMaxId() returns zero or null before I added coalesce. I have two rows in my database with ids 1 and 2. Can anyone help me determine why this doesn't work?
I'm trying to get the latest or max id so that I can use the find method after to return the most recent GenJournal object in my service class.
I'm stumped and really need some options or strategy to determine why this doesn't work.
You could use "Native Query" feature by passing nativeQuery = true param into #Query annotation like this
#Query("select coalesce(max(u.id), 0) from Gen_Journal_Table u", NativeQuery = true)
Long getMaxId();
My issue was two-fold. First I was getting null without the use of "coalesce". That caused me to think that this didn't work. When I adopted the use of "coalesce" I didn't realize that my table had no records and was returning the zero (0). My table in the production profile did have two records and I was expecting an id of 2.
I was manually checking the wrong database and setting expectations that were incorrect.

Invalid Identifier When Editing an ADO Query

I have an ADO query that I use to gather data and later use to update that data. (Embarcadaro C++ Xe2 & Oracle 10g). Rownum (aliased to pgnum) is also selected and in this query. When posting data edited via this query, I receive invalid identifier "pgnum". This seems to be an issue specifically with ADO as this same code worked in previous versions of our software. We recently converted all our queries to ADO from Tquery (old BDE Driven). Adding "pgnum" to the queries persistent fields does not help. Any advice would be greatly appreciated.
Table1 is an ADOQuery.
sql = "SELECT ROWNUM PGNUM, A.* FROM DOCUMENT_IMAGE A WHERE DOCNO = " + String(Form1->qryDocumentDOCNO->AsInteger) + " ORDER BY ROWNUM ";
Table1->Close();
Table1->SQL->Clear();
Table1->SQL->Add(sql);
Table1->Open();
Table1->Edit();
Table1IMAGE->LoadFromFile(filepath);
if (Table1->Modified){
Table1->Post();
}
After tons of research and testing I could get nothing to work while keeping rownum in the query. I'm honestly not sure what it was accomplishing, I took this project over from someone else. Anyway, I removed rownum and used a different field to order the query by, problem solved.

Spring CRUD repository: is there findOneByMaxXYZColumn()?

My requirement:
fetch ONE object (e.g RetainInfo ) from table RETAIN_INFO if VERSION column has max value
Does CRUD repository support for an interface method like
findOneByMaxRetVersionAndCountry("DEFAULT")
Equivalent db2 sql:
select RET_ID, max(ri.RET_VERSION) from RETAIN_INFO ri where ri. COUNTRY='DEFAULT' group by RET_ID fetch first 1 rows only;
This query selects an ID, but I would actually want the RetainInfo object corresponding the SINGLE row returned by the query.
I prefer to get that without using custom query, i.e using findBy or some other method/interface supported by Spring CRUD.
You could use limiting in combination with sorting (spring data reference:limit query results). Declare a method similar to the following in your CrudRepository interface :
RetainInfo findTopByCountryOrderByRetVersionDesc(String country);
You can also use findFirst to get the first result. Before getting the result, make sure to use Orderby and then the ascending(Asc) or descending(Desc). As an example if you want to order by version and retrieve based on productName
RetainInfo findFirstByProductNameOrderByVersionDesc(String productName);
Spring Data doesn't provide an expression to select a max value. All supported query parts could be found in the Spring 1.2.0.RELEASE docs: Appendix A. Namespace reference or line 182 of org.springframework.data.repository.query.parser.Part.
Also feel free to create a feature request at Spring's Jira page.

(Postgres) row_number OVER Partition in 8.2

some time ago I happend to resolve a PG related problem with this SO question of mine.
Basically it's about using row_number over a partition in 8.4.
Sadly now I have to create the same thing for 8.2 since one of my customers is on
8.2 and needs it desperatly.
What I do know (on 8.4) is the following:
SELECT custId, custName, 'xyz-' || row_number() OVER (PARTITION by custId)
AS custCode
Basically counting the occurances of custId and assigning custCodes from that.
(just an example, to show what I to; of course the query is way more complex)
I figured the solutions provided to the question mentioned above, but did'nt get them
working since there's one more hurdle to take. I don't run SQL directly I have to
embed it into a xml based config file which creates a certain xml format from the query
results. So creating temp stuff or procedures is not really an option.
So here's the question, does anyone of you guys have an idea how to port that solution of
mine to PG 8.2?
TIA
K
use depesz solution http://www.depesz.com/index.php/2007/08/17/rownum-anyone-cumulative-sum-in-one-query/