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 067c415

Browse files
authored
Update raise_exception.sql
raise_exception(): type info added to hint, example added
1 parent c526d3d commit 067c415

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

‎functions/raise_exception.sql‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ create or replace function raise_exception(
66
value anyelement,
77
message text default 'Unhandled value',
88
detail text default null,
9-
hint text default 'See value in detail as JSON',
9+
hint text default 'See value (type %s) in detail as JSON',
1010
errcode text default 'raise_exception',
1111
"column" text default null,
1212
"constraint" text default null,
@@ -25,7 +25,7 @@ begin
2525
raise exception using
2626
message = coalesce(message, 'Unhandled value'),
2727
detail = coalesce(detail, coalesce(to_json(value), 'null'::json)::text),
28-
hint = coalesce(hint, 'See value in detail as JSON'),
28+
hint = format(coalesce(hint, 'See value (type %s) in detail as JSON'), pg_typeof(value)::text),
2929
errcode = coalesce(errcode, 'raise_exception'/*ERRCODE_RAISE_EXCEPTION (P0001)*/),
3030
column = coalesce("column", ''),
3131
constraint = coalesce("constraint", ''),
@@ -122,6 +122,18 @@ select case finger
122122
from generate_series(1, 5) as hand(finger);
123123

124124
--USE EXAMPLE 2
125+
select hand1.finger, hand2.finger
126+
from generate_series(1, 5) as hand1(finger)
127+
left join generate_series(1, 4 + 1) as hand2(finger) using (finger)
128+
--we are insured against mistakes:
129+
where case when hand1.finger between 1 and 5
130+
and hand2.finger is not null
131+
then true
132+
else raise_exception(array[hand1.finger, hand2.finger])
133+
end
134+
order by hand1.finger;
135+
136+
--USE EXAMPLE 3
125137
select i
126138
from generate_series(1, 300) as x(i)
127139
where case when clock_timestamp() - statement_timestamp() < '1s'

0 commit comments

Comments
(0)

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