使用原始SQL SELECT命令时出现语法错误

时间:2017-05-30 08:01:26

标签: ruby-on-rails postgresql

我不知道为什么我会收到语法错误,根据this question一切都应该没问题。我找不到一种方法来执行window function(postgres查询返回多列 GROUPED BY 个人列),这就是我使用原始SQL的原因

我仍然是Postgres的新手,但我认为它可能与消毒有关,但我也不知道如何去做。任何帮助将不胜感激,这是我的代码:

module TasksTestQuery

  def self.call

    query = "SELECT user_id, username, date, SUM(user_id) AS total_work, SUM(duration) AS total_duration OVER (PARTITION BY user_id) FROM tasks"

    ActiveRecord::Base.connection.find_by_sql(query)

  end
end

我得到的确切错误是:

ActiveRecord::StatementInvalid
PG::SyntaxError: ERROR: syntax error at or near "(" LINE 1: SELECT user_id, username, date, SUM(user_id) AS total_work, SUM(duration) AS total_duration OVER (PARTITION BY user_id) FROM tasks

1 个答案:

答案 0 :(得分:0)

应该是

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myform" action="https://stackoverflow.com/users/8084795/rohit-bhati" method="POST">
</form>
<select name="tab" form="myform">
  <option value="">Select Tab</option>
  <option value="profile">profile</option>
  <option value="topactivity">activity</option>
</select>