【问题标题】:postgres loop record retrieval syntax errorpostgres 循环记录检索语法错误
【发布时间】:2021-05-17 19:57:07
【问题描述】:

我有这个引发错误的循环:

SQL 错误 [42601]:错误:“.”处或附近的语法错误位置:435

DO
$$DECLARE
declare 
s_row record;
sch cursor for
SELECT  distinct n.nspname as "schema"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE pg_catalog.array_to_string(c.relacl, E'\n') LIKE '%user123%';
begin
    open sch;
    loop
    fetch sch into s_row;
    exit when not found;
    REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA s_row.schema FROM partner_reporting_user3_to_delete;
    end loop;
close sch;
END;$$;

我以为我可以通过说 s_row.schema 来引用记录行内容,但我在这里遗漏了一些东西..

【问题讨论】:

    标签: postgresql loops syntax-error


    【解决方案1】:

    为此尝试动态 SQL。

    ...
    EXECUTE format('REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA %I FROM partner_reporting_user3_to_delete;', s_row.schema);
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 2014-10-14
      • 1970-01-01
      • 2015-08-02
      • 1970-01-01
      相关资源
      最近更新 更多