我有下表:
Table "public.cards"
Column | Type | Modifiers
---------------+-----------------------------+----------------------------------------------------
id | integer | not null default nextval('cards_id_seq'::regclass)
question | text | not null
answer | text | not null
grade | integer |
last_trained | timestamp without time zone |
next_train | integer | not null
times_trained | integer | not null
url | character varying(255) |
user_id | integer |
inserted_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
我尝试在Ecto中构建一个与此对应的查询:
SELECT * FROM cards
WHERE date_part('day', now()-last_trained) > next_train;
答案 0 :(得分:2)
import Ecto.Query
...
from(c in Card, where: fragment("date_part('day', now()-last_trained) > next_train")