Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Unique constraint violations don't populate constraint_name in stacked diagnostics #13501

Open
pkj415 opened this issue Aug 1, 2022 · 0 comments
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@pkj415
Copy link
Contributor

pkj415 commented Aug 1, 2022

Jira Link: DB-3097

Description

The "constraint" field is empty in the below test case:

NOTICE:  function f(text) does not exist, skipping


drop table if exists t cascade;
NOTICE:  table "t" does not exist, skipping


create table t(k serial primary key, v varchar(5) not null);
create unique index t_v_unq on t(v);


insert into t(v) values ('dog'), ('cat'), ('frog');


create function f(new_v in text)
  returns table(z text)
  security definer
  language plpgsql
as $body$
declare
  sqlstate_    text not null := '';
  constraint_  text not null := '';
  msg          text not null := '';
begin
  z := 'Inserting "'||new_v||'"'; return next;
  begin
    insert into t(v) values (new_v);
    z := 'No exception'; return next;
  exception
    when others then
      get stacked diagnostics
        sqlstate_ = returned_sqlstate,
        constraint_ = constraint_name,
        msg = message_text;
      if sqlstate_ = '23505' then
        z := 'unique_violation'; return next;
        z := 'constraint: '||constraint_; return next;
        z := 'message:    '||msg; return next;
      else
        z := 'others'; return next;
        z := 'sqlstate:   '||sqlstate_; return next;
        z := 'message:    '||msg; return next;
    end if;
  end;
end;
$body$;

select z from f('dog');
                                  z                                   
----------------------------------------------------------------------
 Inserting "dog"
 unique_violation
 constraint: 
 message:    duplicate key value violates unique constraint "t_v_unq"
(4 rows)```
@pkj415 pkj415 added area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Aug 1, 2022
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Aug 1, 2022
@yugabyte-ci yugabyte-ci removed the status/awaiting-triage Issue awaiting triage label Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

2 participants