Search Postgresql Archives

Re: Dynamically filtering a CTE?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Apr 20, 2018 at 9:22 AM, W. Trevor King <wking@xxxxxxxxxx> wrote:
format('
    WITH RECURSIVE _ancestors(id, ancestors) AS (
        SELECT
          item.id AS id,
          ARRAY[item.ancestor_id] AS ancestors
        FROM items AS item
        %s
​[...]​

    ', condition);

  SELECT * FROM ancestors('WHERE item.id = 62324721');

​Just keep in mind that this opens up a huge SQL-injection hole in your database.  Depending on how its called you might want to validation the input text for both whitelist and blacklist items before executing it.

David J.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux