如何在 Ecto 查询中使用列值?
How to use a column value in an Ecto query?
我有以下 table:
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;
import Ecto.Query
...
from(c in Card, where: fragment("date_part('day', now()-last_trained) > next_train")
我有以下 table:
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;
import Ecto.Query
...
from(c in Card, where: fragment("date_part('day', now()-last_trained) > next_train")