Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 60d53a7

Browse files
authored
schema added, notice -> warnig
1 parent 634cb19 commit 60d53a7

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

‎functions/is_sql.sql‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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)
22
returns boolean
33
returns null on null input
44
parallel unsafe --(ERROR: cannot start subtransactions during a parallel operation)
@@ -60,45 +60,46 @@ BEGIN
6060

6161
EXECUTE sql;
6262
EXCEPTION WHEN others THEN
63-
IF is_notice THEN
63+
IF is_warning THEN
6464
GET STACKED DIAGNOSTICS
6565
exception_sqlstate := RETURNED_SQLSTATE,
6666
exception_message := MESSAGE_TEXT,
6767
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;
7171
END IF;
7272
RETURN FALSE;
7373
END;
7474
RETURN TRUE;
7575
END
7676
$$;
7777

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';
7979

8080
-- TEST
8181
do $do$
8282
begin
8383
--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
9191

9292
--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');
102103
end;
103104
$do$;
104105

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /