|
1 | | -CREATE OR REPLACE FUNCTION is_sql(sql text, is_notice boolean default false) |
| 1 | +CREATE OR REPLACE FUNCTION public.is_sql(sql text, is_warning boolean default false) |
2 | 2 | returns boolean |
3 | 3 | returns null on null input |
4 | 4 | parallel unsafe --(ERROR: cannot start subtransactions during a parallel operation) |
@@ -60,45 +60,46 @@ BEGIN |
60 | 60 |
|
61 | 61 | EXECUTE sql; |
62 | 62 | EXCEPTION WHEN others THEN |
63 | | - IF is_notice THEN |
| 63 | + IF is_warning THEN |
64 | 64 | GET STACKED DIAGNOSTICS |
65 | 65 | exception_sqlstate := RETURNED_SQLSTATE, |
66 | 66 | exception_message := MESSAGE_TEXT, |
67 | 67 | exception_context := PG_EXCEPTION_CONTEXT; |
68 | | - RAISE NOTICE 'exception_sqlstate = %', exception_sqlstate; |
69 | | - RAISE NOTICE 'exception_context = %', exception_context; |
70 | | - RAISE NOTICE 'exception_message = %', exception_message; |
| 68 | + RAISE WARNING 'exception_sqlstate = %', exception_sqlstate; |
| 69 | + RAISE WARNING 'exception_context = %', exception_context; |
| 70 | + RAISE WARNING 'exception_message = %', exception_message; |
71 | 71 | END IF; |
72 | 72 | RETURN FALSE; |
73 | 73 | END; |
74 | 74 | RETURN TRUE; |
75 | 75 | END |
76 | 76 | $$; |
77 | 77 |
|
78 | | -COMMENT ON FUNCTION is_sql(sql text, is_notice boolean) IS 'Check SQL syntax exactly in your PostgreSQL version'; |
| 78 | +COMMENT ON FUNCTION public.is_sql(sql text, is_warning boolean) IS 'Check SQL syntax exactly in your PostgreSQL version'; |
79 | 79 |
|
80 | 80 | -- TEST |
81 | 81 | do $do$ |
82 | 82 | begin |
83 | 83 | --positive |
84 | | - assert is_sql('SELECT x/*--;*/ ; '); |
85 | | - assert is_sql('SELECT x ; --'); |
86 | | - assert is_sql('SELECT -- ; '); |
87 | | - assert is_sql('SELECT ; /*select ;*/ --'); |
88 | | - assert is_sql('ABORT'); |
89 | | - assert is_sql($$do ''$$); |
90 | | - assert is_sql(pg_catalog.pg_get_functiondef('public.is_sql'::regproc::oid)); --self test |
| 84 | + assert public.is_sql('SELECT x/*--;*/ ; '); |
| 85 | + assert public.is_sql('SELECT x ; --'); |
| 86 | + assert public.is_sql('SELECT -- ; '); |
| 87 | + assert public.is_sql('SELECT ; /*select ;*/ --'); |
| 88 | + assert public.is_sql('ABORT'); |
| 89 | + assert public.is_sql($$do ''$$); |
| 90 | + assert public.is_sql(pg_catalog.pg_get_functiondef('public.is_sql'::regproc::oid)); --self test |
91 | 91 |
|
92 | 92 | --negative |
93 | | - assert not is_sql(''); |
94 | | - assert not is_sql('do'); |
95 | | - assert not is_sql('123'); |
96 | | - assert not is_sql('SELECT !'); |
97 | | - assert not is_sql('SELECT ;;'); |
98 | | - assert not is_sql('SELECT ; ; /*select ;*/ --'); |
99 | | - assert not is_sql(' --select 1 '); |
100 | | - assert not is_sql(' /*select 1*/ '); |
101 | | - assert not is_sql('return unknown'); |
| 93 | + assert not public.is_sql(''); |
| 94 | + assert not public.is_sql('do'); |
| 95 | + assert not public.is_sql('123'); |
| 96 | + assert not public.is_sql('SELECT !'); |
| 97 | + assert not public.is_sql('-------'); |
| 98 | + assert not public.is_sql('SELECT ;;'); |
| 99 | + assert not public.is_sql('SELECT ; ; /*select ;*/ --'); |
| 100 | + assert not public.is_sql(' --select 1 '); |
| 101 | + assert not public.is_sql(' /*select 1*/ '); |
| 102 | + assert not public.is_sql('return unknown'); |
102 | 103 | end; |
103 | 104 | $do$; |
104 | 105 |
|
|
0 commit comments