将本地设置为先前存储的值

时间:2019-09-24 10:03:50

标签: postgresql settings plpgsql lock-timeout

我想在我的PL / pgSQL函数中临时更改CREATE OR REPLACE FUNCTION public.myfunction() RETURNS void AS $body$ DECLARE l_tmp_lock_timeout TEXT; BEGIN -- We want this to bail out when no lock is gained SHOW lock_timeout INTO l_tmp_lock_timeout; SET LOCAL lock_timeout TO '10s'; RAISE NOTICE 'Local lock timeout set to 10s, was %', l_tmp_lock_timeout; -- ... do stuff ... -- and reset the lock timeout SET LOCAL lock_timeout TO l_tmp_lock_timeout; RAISE NOTICE 'Local lock timeout set to %', l_tmp_lock_timeout; RETURN; END; $body$ LANGUAGE 'plpgsql' ,我想这很简单:

NOTICE:  Local lock timeout set to 10s, was 0
ERROR:  invalid value for parameter "lock_timeout": "l_tmp_lock_timeout"
CONTEXT:  SQL statement "SET LOCAL lock_timeout TO l_tmp_lock_timeout"
PL/pgSQL function myfunction() line 48 at SQL statement

但这给了我这个结果:

lock_timeout

如何正确存储和重置private const string EncryptionKey = "SomeSecretKEY"; private readonly static byte[] Salt = Encoding.ASCII.GetBytes(EncryptionKey.Length.ToString()); public static String EncryptPassword(string password) { var rijndaelCipher = new RijndaelManaged(); byte[] plainText = Encoding.Unicode.GetBytes(password); var secretKey = new PasswordDeriveBytes(EncryptionKey, Salt); using (ICryptoTransform encryptor = rijndaelCipher.CreateEncryptor(secretKey.GetBytes(32), secretKey.GetBytes(16))) { using (var memoryStream = new MemoryStream()) { using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)) { cryptoStream.Write(plainText, 0, plainText.Length); cryptoStream.FlushFinalBlock(); return Convert.ToBase64String(memoryStream.ToArray()); } } } } 设置?

1 个答案:

答案 0 :(得分:2)

SET之类的实用程序语句不能与参数一起使用。

您将不得不使用动态SQL,例如

EXECUTE format('SET lock_timeout = %L', l_tmp_lock_timeout);

或使用

SELECT set_config('lock_timeout', l_tmp_lock_timeout, FALSE);