简体   繁体   English

Postgres ltree 查询以使用列名在层次结构之后获取数据

[英]Postgres ltree Query to fetch data after the hierarchy using column name

I wanted to fetch Postgres ltree hierarchy after certain level using subltree and column name.我想使用 subltree 和列名在某个级别之后获取 Postgres ltree 层次结构。 I am able to fetch when i provide the exact input but not able to do so with column name.当我提供确切的输入但无法使用列名时,我能够获取。

This is working fine:这工作正常:

select *
from audit.EMPLOYEE_TOTALS_BY_DAY_WITHOUT_FP_MV_V4
where ecd_path ~ '10130882.11000114.10152749.10148495.10125148.*{1,}'
  and customer_id = 2955
limit 10; 

But this is not.但这不是。 Please correct me with right query请用正确的查询纠正我

select *
from audit.EMPLOYEE_TOTALS_BY_DAY_WITHOUT_FP_MV_V4
where ecd_path ~ subltree(ecd_path, 0, nlevel(ecd_path)-1)'.*{1,}'
  and customer_id = 2955
limit 10;
;

I am very new to Postgres Ltree .我对 Postgres Ltree 很陌生。 Correct me if anything is wrong here如果这里有任何问题,请纠正我

If your goal is to return everything whose path is more than 5 labels deep, then it would seem that this could be accomplished by doing:如果您的目标是返回路径深度超过 5 个标签的所有内容,那么这似乎可以通过执行以下操作来实现:

    select *
    from audit.EMPLOYEE_TOTALS_BY_DAY_WITHOUT_FP_MV_V4
    where nlevel(ecd_path) > 5
    and customer_id = 2955
    limit 10;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM