如何在春季启动时从PostgreSQL获取特定的列

时间:2018-12-04 07:49:33

标签: postgresql jpa

我正在使用Postgres数据库。我想从表中获取特定的列。 在PgAdmin III中执行以下查询时,它工作正常,但会引发异常

  

org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:(靠近第2行,第56列

通过JAVA代码执行时。

查询:

SELECT 40 AS client_id,
       0 AS account_id,
       0 AS search_engine_id,
       'present' AS date_type,
       coalesce(stats.clicks, 0) AS clicks,
       d.day AS date
FROM (
  SELECT generate_series(timestamp '2018-06-10', timestamp '2018-06-16', interval '1 day')::date
) d (day)
  LEFT JOIN (
    SELECT 40 AS client_id,
           0 AS account_id,
           0 AS search_engine_id,
           date_type,
           sum(clicks) AS clicks,
           to_date(date, 'YYYY-MM-dd') AS date
    FROM ne_email_stats
    WHERE client_id = 40
      AND account_id IN (13, 14)
      AND date BETWEEN '2018-06-10'   AND '2018-06-16'
    GROUP BY date,
             date_type
  ) stats ON stats.date = d.day
ORDER BY date ASC

要执行查询的代码:

Query query = em.createQuery(pSqlQuery, EmailReportStats.class);
           emailReportStatses = query.getResultList();
           if (!emailReportStatses.isEmpty()) {
               for (EmailReportStats emailReport : emailReportStatses) {
                   emailReport.setDate(LocalDate.parse(emailReport.getDate()).format(DateTimeFormatter.ofPattern("dd MMM")));
                   emailReportStats.add(emailReport);
               }

0 个答案:

没有答案