ON CONFLICT DO UPDATE当我尝试在FROM语句中使用多个源时,我在Postgres 9.5中遇到了问题.
工作代码示例:
INSERT INTO new.bookmonographs (citavi_id, abstract, createdon, edition, title, year)
SELECT "ID", "Abstract", "CreatedOn"::timestamp, "Edition", "Title", "Year"
FROM old."Reference"
WHERE old."Reference"."ReferenceType" = 'Book'
AND old."Reference"."Year" IS NOT NULL
AND old."Reference"."Title" IS NOT NULL
ON CONFLICT (citavi_id) DO UPDATE
SET (abstract, createdon, edition, title, year) = (excluded.abstract, excluded.createdon, excluded.edition, excluded.title, excluded.year)
;
Run Code Online (Sandbox Code Playgroud)
错误的代码:
INSERT INTO new.bookmonographs (citavi_id, abstract, createdon, edition, title, year)
SELECT "ID", "Abstract", "CreatedOn"::timestamp, "Edition", "Title", "Year"
FROM old."Reference", old."ReferenceAuthor"
WHERE …Run Code Online (Sandbox Code Playgroud) 我正在尝试在PostgreSQL中执行以下操作
INSERT INTO blog_sums ( blog_id, date, total_comments)
SELECT blog_id, '2016-09-22', count(comment_id) as total_comments_update
FROM blog_comments
WHERE date = '2016-09-22'
GROUP BY blog_id
ON CONFLICT (blog_id ,date)
DO UPDATE SET blog_sums.total_comments = total_comments_update;
Run Code Online (Sandbox Code Playgroud)
我在日期+ blog_id上有唯一的密钥,我一直收到错误:
错误:列"total_comments_update"不存在
在这种情况下,我正在寻找"正确"的方式和最有效的方法来更新重复/冲突
我的桌子是
blog_comments (blog_id, comment_id, comment, date)
blog_sums ( blog_id, date, total_comments) . unique on blog_id+date
Run Code Online (Sandbox Code Playgroud)
谢谢
我有以下类型,并希望使它成为一个Functor:
newtype SubsM a = SubsM {runSubsM :: Context -> Either Error (a, Env)}
Run Code Online (Sandbox Code Playgroud)
到目前为止我得到了这个
instance Functor SubsM where
fmap f (SubsM a) = SubsM (\s->(Right((f a),(fst s))))
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,因为a不是预期的类型,我的问题是我如何在左侧模式匹配a?