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

[MySQL] Datatype mismatch in objects causing issues #690

Open
shubham-yb opened this issue Dec 19, 2022 · 0 comments
Open

[MySQL] Datatype mismatch in objects causing issues #690

shubham-yb opened this issue Dec 19, 2022 · 0 comments
Assignees
Labels
dep-issue Issues with dependencies

Comments

@shubham-yb
Copy link
Contributor

shubham-yb commented Dec 19, 2022

Due to the different datatype mapping, example INT is parsed as BIGINT from MYSQL, it has created an issue where certain functions are concerned since their body is passed as is and a type mismatch occurs.

Please consider this example below for better understanding.

drop table if exists bar;
create table bar(
      id int, 
      p_name varchar(10)
);

drop function if exists foo;
delimiter //

create function foo (p_id int)
returns varchar(20)
reads sql data
begin
return (
select p_name from bar where p_id=id
);
end//

delimiter ;

CREATE OR REPLACE VIEW v1 
as 
select foo(id) as p_name 
from bar;

This schema when exported, is exported as:

CREATE TABLE bar (
        id bigint,
        p_name varchar(10)
) ;

CREATE OR REPLACE FUNCTION foo (p_id integer) RETURNS varchar AS $body$
BEGIN
return(select p_name from bar where p_id=id);
end;
$body$
LANGUAGE PLPGSQL
SECURITY DEFINER
;

CREATE OR REPLACE VIEW v1 AS select foo(bar.id) AS p_name FROM bar;


The table and the function get created fine. But the view creation errors out with:

ERROR:  function foo(bigint) does not exist
LINE 1: CREATE OR REPLACE VIEW v1 AS select foo(bar.id) AS p_name F...
                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

As you can see, since the table column is of type BIGINT but the parameter is INT, it errors out.

The same view definition if run as:

CREATE OR REPLACE VIEW v1 AS select foo(bar.id::integer) AS p_name FROM bar;

Will work fine.

@shubham-yb shubham-yb added documentation Improvements or additions to documentation dep-issue Issues with dependencies labels Dec 19, 2022
@github-actions github-actions bot added the triage Needs to be triaged label Dec 19, 2022
@shubham-yb shubham-yb removed the triage Needs to be triaged label Dec 20, 2022
@shubham-yb shubham-yb removed the documentation Improvements or additions to documentation label Jan 10, 2023
@shubham-yb shubham-yb removed their assignment Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dep-issue Issues with dependencies
Projects
None yet
Development

No branches or pull requests

3 participants