有没有办法将一长行 PL/pgSQL 代码拆分成多行?我的上下文是一个触发器函数,我按照以下方式将插入记录到表中:
INSERT INTO insert_log (log_time, description)
VALUES (
now()
, 'A description. Made up of 3 semi long sentences. That I want to split, in the code, not in the log table, over 3 lines for readability.'
);
Run Code Online (Sandbox Code Playgroud) 我已经按照以下方式donor
在架构中创建了表reference
:
CREATE TABLE reference.donor (
donor_code smallint PRIMARY KEY,
donor_name character varying NOT NULL,
donor_type smallint REFERENCES reference.donor_type (type_id),
alpha_2_code char(2) REFERENCES reference.iso_3166_1 (alpha_2_code)
);
Run Code Online (Sandbox Code Playgroud)
我已经按照以下方式填充了表格:
INSERT INTO reference.donor (donor_code, donor_name, donor_type, alpha_2_code)
SELECT donor_code, donor_name, donor_type, alpha_2_code
FROM reference.donor_template;
Run Code Online (Sandbox Code Playgroud)
当我运行时:
\dt+ reference.*
Run Code Online (Sandbox Code Playgroud)
在 psql 我看到reference.donor
表:
List of relations
Schema | Name | Type | Owner | Size | Description
-----------+----------------+-------+----------+-------+-------------
reference | donor | table | postgres | 16 kB |
reference | …
Run Code Online (Sandbox Code Playgroud) 我正在尝试查找EXECUTE
和ALL
之间的区别的参考资料:
GRANT { EXECUTE | ALL [ PRIVILEGES ] } ON { FUNCTION | ALL FUNCTIONS IN SCHEMA }...
Run Code Online (Sandbox Code Playgroud)
但我能找到的只是文档所说的:
EXECUTE 允许使用指定的函数以及使用在该函数之上实现的任何运算符。这是唯一适用于函数的特权类型。(此语法也适用于聚合函数。)
例如,我知道对于模式ALL = CREATE + USAGE
,但我想在函数引用中仔细检查:
这是唯一适用于函数的特权类型。
在上面的文档片段中暗示了对于函数ALL = EXECUTE
并且:
GRANT ALL ON ALL FUNCTIONS...
Run Code Online (Sandbox Code Playgroud)
相当于:
GRANT EXECUTE ON ALL FUNCTIONS...
Run Code Online (Sandbox Code Playgroud) 我有一个deflator
定义为的表:
Table "deflator"
Column | Type | Modifiers
-------------+-------------------+-----------
country_code | smallint | not null
country_name | character varying | not null
year | smallint | not null
deflator | numeric |
source | character varying |
Run Code Online (Sandbox Code Playgroud)
此表的示例输出如下所示:
country_code | country_name | year | deflator | source
-------------+---------------+------+----------+----------
1 | country_1 | 2016 | 12 | source_1
1 | country_1 | 2015 | 11 | source_2
1 | country_1 | 2014 | 10 | source_2
2 | country_2 …
Run Code Online (Sandbox Code Playgroud)