SHOW WARNINGS/ERRORS

功能描述

显示有关存储函数的信息。

注意事项

  • 添加的系统参数sql_note,是设置show warnings是否显示Note级别的信息开关。

  • Code字段是信息的错误码。其数字含义对应ERRCODE中的宏定义。其中各种信息的状态宏都是由 MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)生成。MAKE_SQLSTATE作用是把字符 ch1 ~ ch5 的ascii码减去’0’,再取其二进制的后六位得到 res1 ~ res5,然后把这5个数据从低到高位组成一个30位二进制结果(res5res4res3res2res1),转换成一个十进制数字,即就是错误码的数字。 不同的错误码数字对应不同的状态宏。

语法格式

  1. SHOW WARNINGS [LIMIT [offset,] row_count]
  2. SHOW COUNT(*) WARNINGS
  3. SHOW ERRORS [LIMIT [offset,] row_count]
  4. SHOW COUNT(*) ERRORS

参数说明

  • row_count

    输出上条sql,生成的warnings/errors信息的行数限制。

  • offset

    从第几行信息开始显示。

  • 添加系统参数

    sql_note 该参数是设置show warnings是否显示Note级别的信息开关

返回结果集

字段名类型说明
Level字符类型信息的级别(Note/Warning/Error)
Code整数类型信息状态对应的错误码
Message字符类型信息内容

示例

  1. openGauss=# show sql_note;
  2. sql_note
  3. ----------
  4. on
  5. (1 row)
  6. openGauss=# create table test(id int, name varchar default 11);
  7. CREATE TABLE
  8. openGauss=# create table test(id int, name varchar default 11);
  9. ERROR: relation "test" already exists in schema "public"
  10. DETAIL: creating new table with existing name in the same schema
  11. openGauss=# show warnings limit 1;
  12. level | code | message
  13. -------+-----------+---------------------------------------------------
  14. Error | 117571716 | relation "test" already exists in schema "public"
  15. (1 row)
  16. openGauss=# show count(*) warnings;
  17. count
  18. -------
  19. 1
  20. (1 row)
  21. openGauss=# CREATE OR REPLACE FUNCTION TEST_FUNC(tempdata char) RETURNS VOID AS $$
  22. openGauss$# BEGIN
  23. openGauss$# raise info'TEST CHAR VALUE IS %',tempdata;
  24. openGauss$# END;
  25. openGauss$# $$ LANGUAGE plpgsql;
  26. CREATE FUNCTION
  27. openGauss=# select TEST_FUNC('abc'::clob);
  28. INFO: TEST CHAR VALUE IS abc
  29. CONTEXT: referenced column: test_func
  30. test_func
  31. -----------
  32. (1 row)
  33. openGauss=# show warnings;
  34. level | code | message
  35. -------+------+------------------------
  36. Note | 0 | TEST CHAR VALUE IS abc
  37. (1 row)
  38. openGauss=# set sql_note=false;
  39. SET
  40. openGauss=# select TEST_FUNC('abc'::clob);
  41. INFO: TEST CHAR VALUE IS abc
  42. CONTEXT: referenced column: test_func
  43. test_func
  44. -----------
  45. (1 row)
  46. openGauss=# show warnings;
  47. level | code | message
  48. -------+------+---------
  49. (0 rows)
  50. openGauss=# SELECT pg_advisory_unlock(1), pg_advisory_unlock_shared(2), pg_advisory_unlock(1, 1), pg_advisory_unlock_shared(2, 2);
  51. WARNING: you don't own a lock of type ExclusiveLock
  52. CONTEXT: referenced column: pg_advisory_unlock
  53. WARNING: you don't own a lock of type ShareLock
  54. CONTEXT: referenced column: pg_advisory_unlock_shared
  55. WARNING: you don't own a lock of type ExclusiveLock
  56. CONTEXT: referenced column: pg_advisory_unlock
  57. WARNING: you don't own a lock of type ShareLock
  58. CONTEXT: referenced column: pg_advisory_unlock_shared
  59. pg_advisory_unlock | pg_advisory_unlock_shared | pg_advisory_unlock | pg_advisory_unlock_shared
  60. --------------------+---------------------------+--------------------+---------------------------
  61. f | f | f | f
  62. (1 row)
  63. openGauss=# show warnings;
  64. level | code | message
  65. ---------+------+--------------------------------------------
  66. Warning | 64 | you don't own a lock of type ExclusiveLock
  67. Warning | 64 | you don't own a lock of type ShareLock
  68. Warning | 64 | you don't own a lock of type ExclusiveLock
  69. Warning | 64 | you don't own a lock of type ShareLock
  70. (4 rows)
  71. openGauss=# show warnings limit 2, 4;
  72. level | code | message
  73. ---------+------+--------------------------------------------
  74. Warning | 64 | you don't own a lock of type ExclusiveLock
  75. Warning | 64 | you don't own a lock of type ShareLock
  76. (2 rows)

(3 rows)

  1. ```sql
  2. --用sql_note控制存储note信息的开关。
  3. CREATE OR REPLACE FUNCTION TEST_FUNC(tempdata char) RETURNS VOID AS $$
  4. BEGIN
  5. raise info'TEST CHAR VALUE IS %',tempdata;
  6. END;
  7. $$ LANGUAGE plpgsql;
  8. select TEST_FUNC('abc'::clob);
  9. INFO: TEST CHAR VALUE IS abc
  10. CONTEXT: referenced column: test_func
  11. test_func
  12. -----------
  13. (1 row)
  14. show warnings;
  15. level | code | message
  16. -------+------+------------------------
  17. Note | 0 | TEST CHAR VALUE IS abc
  18. (1 row)
  19. set sql_note=false;
  20. select TEST_FUNC('abc'::clob);
  21. INFO: TEST CHAR VALUE IS abc
  22. CONTEXT: referenced column: test_func
  23. test_func
  24. -----------
  25. (1 row)
  26. show warnings;
  27. level | code | message
  28. -------+------+---------
  29. (0 rows)