ERROR: return type mismatch in function declared to return

user3808157

Building on these tables:

create table f1_driver(
 code varchar(5) not null primary key,
 name varchar(10),
 surname varchar(20),
 dateofbirth date,
 debut integer,
 countryoforigin varchar(20),
 points integer
);

create table f1_results (
 drivercode varchar(5) not null references f1_driver,
 circuitcode varchar(5) not null references f1_circuit,
 racedate date,
 raceposition integer,
 grid integer,
 primary key (drivercode, circuitcode,  racedate)
);

I want to make a function that the user will give the circuitcode and the function will return the name and surname of the drivers that in this specific circuit the raceposition was better than the grid.

I write this:

CREATE FUNCTION get(character) RETURNS SETOF f1_driver AS
$$
SELECT  D.name, D.surname
FROM f1_driver D,f1_results R
WHERE R.circuitcode = $1
AND D.code=R.drivercode
AND R.raceposition<grid ;
$$ LANGUAGE SQL;

And I have this error:

ERROR:  return type mismatch in function declared to return f1_driver
DETAIL:  Final statement returns too few columns.
CONTEXT:  SQL function "get"
Erwin Brandstetter

The row type f1_driver does not match what you actually return. Use RETURNS TABLE to provide a matching declaration:

CREATE FUNCTION f_get_drivers(varchar)
  RETURNS TABLE(name varchar, surname varchar) AS
$func$
SELECT D.name, D.surname
FROM   f1_driver D
JOIN   f1_results R ON R.drivercode = D.code
WHERE  R.circuitcode = $1
AND    R.raceposition < R.grid;
$func$ LANGUAGE sql;

Major points

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ERROR: return type mismatch in function declared to return

From Dev

`Error: Return type mismatch of function` in Fortran 95

From Dev

`Error: Return type mismatch of function` in Fortran 95

From Dev

VBA Boolean Function type mismatch on return

From Dev

error: function declared 'noreturn' should not return

From Dev

VB Type Mismatch 'Return'

From Dev

Return type mismatch (or not)

From Dev

Recursive function return type error

From Dev

Function return type mismatch phenomenon when returning different input ranges

From Dev

Function return type mismatch phenomenon when returning different input ranges

From Dev

typescript function declared a non-void type but has no return expression

From Dev

ParamConverterProvider method return type mismatch

From Dev

Android ASyncTask Return type mismatch

From Dev

Haskell newbie: Return type mismatch

From Dev

Typescript throws error for return function type

From Dev

"overloaded function differs only by return type" error

From Dev

flatMap function and return type error in Scala

From Dev

Java generic abstract class return type mismatch

From Dev

Dynamic return type of implementation declared in abstract method

From Java

Obtaining the return type of a function

From Java

Can a function return a type?

From Dev

Enforce Return Type in Function

From Dev

Return type for this function

From Dev

PgAdmin Function return type

From Dev

typedefing a function return type

From Dev

No Return type for function?

From Dev

XSLT Function Return Type

From Dev

Return type of function in java

From Dev

PgAdmin Function return type