如何在Postgres中解析布尔的表达方式?
我有一个表,该表以“代码”为逗号分隔的值。下面的样本值 -
3fa, n38, iw9, 94a, l2v, 20z
92z, 29r, 02z, 99w, 00b, 92i
我想根据布尔表达(带有BODMAS规则)找到相关的行
示例1: 如果输入为(3FA+N38)-02Z ,则该条件应转化为“查找所有具有3FA和N38的记录,但不是02Z”。因此,这将返回第一行。
示例2: 输入为(((((((92Z+00b)-20z)/02Z)/02Z)该条件应转换为“查找所有具有92Z和00B的记录,而不是20z或具有02Z的记录。
如果 操作员的翻译如下
+
被视为包含-
被视为不包含/
被视为将其视为或
我们具有存储的灵活性代码作为逗号分隔的值,或者作为字符串数组。 。
I have a table that has a column "codes" as comma-separated values. Sample values below -
3fa, n38, iw9, 94a, l2v, 20z
92z, 29r, 02z, 99w, 00b, 92i
I want to find relevant rows, based on a boolean expression (with BODMAS rule)
Example 1:
If the input is (3fa+n38)-02z, the condition should translate to "find all records that have 3fa and n38, but not 02z". So this will return the first row.
Example 2:
If the input is (((92z+00b)-20z)/02z) the condition should translate to "find all records that have 92z and 00b, but not 20z OR records that have 02z.
So, the operators translation is as below
+
is treated as CONTAINS-
is treated as NOT CONTAINS/
is treated as OR
We have the flexibility of storing this codes column as either a comma separated value or as a string array. I am trying to build a Postgres function for it. I made it work via. dynamic SQL and REGEXP_REPLACE, but wanted to check if there was a more elegant way of doing it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论