English 中文(简体)
邮局的交易中是否有一项程序?
原标题:Does a procedure run in a transaction in PostgreSQL?

如果一项程序在中间失败,从“特殊产品”开始起,当时的变化是暗中进行的,或者我们是否必须起草任何明确的法典,以确保特殊产品仅在交易中进行?

问题回答

该术语经常被错误地用于指Functions (CREATE FUNCTION),该词提供了与RDBMS提供的其他“存储程序”相同的许多功能(以及更多的功能)。

Real stored procedures (:CREATE PROCEDURE) 采用ISO/IEC标准中规定的标准。 Postgres 11。 主要差异(除其他之外)是交易处理。 见:

其中有的always在交易中运行. 。 手册:

PostgreSQL actually treats every SQL statement as being executed within a transaction. If you do not issue a BEGIN command, then each individual statement has an implicit BEGIN and (if successful) COMMIT wrapped around it.

Functions

页: 1 页: 1

而PL/pgSQL.

By default, any error occurring in a PL/pgSQL function aborts execution of the function and the surrounding transaction. You can trap errors and recover from them by using a BEGIN block with an EXCEPTION clause.

Do not confuse

Procedures

......允许<代码>COMMIT——立即启动新的交易。

A new transaction starts out with default transaction characteristics such as transaction isolation level. In cases where transactions are committed in a loop, it might be desirable to start new transactions automatically with the same characteristics as the previous one. The commands COMMIT AND CHAIN and ROLLBACK AND CHAIN accomplish this.

Exceptions

诸如VACUUM、CRE DATABASECREATE INDEX CONCURRENTLY等指挥系统在交易环境下运作,不得在任何内部进行。

Some things can never be rolled back, including:

如果你使用以下14项程序:

CREATE OR REPLACE PROCEDURE test_error(schema_name text)
LANGUAGE plpgsql
AS
$$
declare
<declare any vars that you need>
BEGIN
<do your thing>
END
$$;

就所有实际用途而言,在<条码>BEGIN和<条码>栏目之间书写的代码在一次交易中执行。 因此,如果栏目中的任何发言都失败,所有以前的发言将自动撤回。 你不需要明确写出任何滚动代码。

然而,有特殊的情况是,人们可以在何时开始/开始/进行回转交易时对谷物控制进行罚款。 Refer to : ,详见。

一项程序在交易中进行,如果存在错误,交易就会得到支持。

例如,你创立了<条码>my_proc(),规定了<条码>5至<条码>。 然后,可生成<代码>,按0分列。 如下所示错误:

CREATE PROCEDURE my_proc(INOUT value INTEGER) AS $$
BEGIN
SET my.var = 5; -- Here
SELECT 1/value INTO value;
END;
$$ LANGUAGE plpgsql;

首先,请在<代码>2至my.var上查询my_proc(1),然后在<代码>5上打上<编码>。 成功如下:

postgres=# SET my.var = 2;
SET
postgres=# CALL my_proc(1);
 my_func
---------
       1
(1 row)
postgres=# SELECT current_setting( my.var );
 current_setting
-----------------
 5
(1 row)

如今,你将<代码>2 至my.var,然后打电话my_proc(0) ,然后在<0/code>误差上打<代码>。

postgres=# SET my.var = 2;
SET
postgres=# CALL my_proc(0);
ERROR:  division by zero
...
postgres=# SELECT current_setting( my.var );
 current_setting
-----------------
 2
(1 row)




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签