问题实际上是关于 sql 查询的优化。假设我们有这样定义的表。
CREATE TYPE record_type AS ENUM (
'TRANSFER',
'TRADE',
'VOUCHER'
);
CREATE TYPE record_status AS ENUM (
'NEW',
'VALIDATED',
'EXPIRED'
);
CREATE TABLE good_records (
id uuid PRIMARY KEY,
user_id uuid NOT NULL,
type record_type NOT NULL,
status record_status NOT NULL,
amount numeric(36,18) NOT NULL DEFAULT 0,
expired_at timestamp WITH TIME ZONE NOT NULL,
notification_sent boolean DEFAULT false,
);
Run Code Online (Sandbox Code Playgroud)
我想每 10 分钟运行一次过期检查,即我会运行SELECT * FROM good_records
where record_status = 'NEW' and notification_sent = false
(和SELECT * FROM …
我已经搜索了该网站,但没有找到我关于子字符串替换的特定问题的合适答案。我知道如何通过替换子字符串/正则表达式clojure.string/replace
但不确定在这种情况下使用它。
让我们说。我首先有一些字符串:
(def test-str "I am a test string. :name to replace, :age to replace. And there are strange symbols in this string. And here are the keyword shall not modify, such as :not-interested.")
(def another-test-str ":nothing :to :replace")
Run Code Online (Sandbox Code Playgroud)
我有一个翻译表:
(def translation-table {:name "Alice"
:age 19})
Run Code Online (Sandbox Code Playgroud)
我想,以取代:name
在test-str
与“爱丽丝”,:age
与19,但不希望更换:not-interested
。表很长,不同的字符串(要替换)包含不同的关键字。
鉴于翻译表,那么进行子串替换的可能系统方法是什么?即,我想要一个函数replace-with-translation
:
(replace-with-translation test-str translation-table)
=> "I am a test string. Alice to replace, 19 to replace. And there are strange symbols …
Run Code Online (Sandbox Code Playgroud)