如何在Postgres中解析布尔的表达方式?

发布于 2025-02-02 22:53:33 字数 593 浏览 2 评论 0原文

我有一个表,该表以“代码”为逗号分隔的值。下面的样本值 -

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文