@@ -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 ,
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
122122from 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
125137select i
126138from generate_series(1 , 300 ) as x(i)
127139where case when clock_timestamp() - statement_timestamp() < ' 1s'
0 commit comments