0

I try to get this function running. When I use pgadmin and manually call this function with

SELECT calculate_something(7) or SELECT common.calculate_something(7)

ERROR: function calculate_something(integer) doesn't exist hint no function matches the given name and argument types (translated from german)

I already tried to cast the call SELECT calculate_something(cast(7 as bigint));

What is wrong with that function or cast? :/

CREATE OR REPLACE FUNCTION common.calculate_something(id bigint)
  RETURNS real AS
$BODY$
  DECLARE
    some_value_out REAL := 20;
  BEGIN
    -- I already removed that part for bug fixing and return a constant value (20)
    RETURN some_value_out;
  END;
$BODY$
  LANGUAGE plpgsql VOLATILE;
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Kody
  • 1,154
  • 3
  • 14
  • 31
  • Works for me. Check if function is created successfully and check if you are connected to right database. – partlov Mar 21 '16 at 08:57
  • And if you are working with autocommit off, make sure you `commit` your `create function` statement –  Mar 21 '16 at 08:58
  • What pg version do you use? – devanand Mar 21 '16 at 09:02
  • I'm using version 9.4.5 on a debian machine. – Kody Mar 21 '16 at 09:04
  • If you are using an another schema than `public` did you grant all required rights? http://www.postgresql.org/docs/9.4/static/sql-grant.html – devanand Mar 21 '16 at 09:06
  • For testing purposes I granted all (`grant all on database postgres to myusername;`). – Kody Mar 21 '16 at 09:15
  • And yes, I commited the function. – Kody Mar 21 '16 at 10:35
  • Are you perhaps using a program such as navicat and typing this in after selecting a particular schema? A lot of people don't realise that programs like this automatically set the search path, so a non-schema defined function may end up inside something other than intended. Also your select statement does not list the schema in the function call. – Lucas Mar 21 '16 at 11:02
  • Never heared of that program :) I'm just using pgadmin and sometimes DataGrip (from jetbrains)... and all I do is executing select statements. not even inserts or deletes. – Kody Mar 21 '16 at 11:11
  • I already solved that problem. I moved the function into another schema yesterday and forgot about that. sry guys. – Kody Mar 21 '16 at 12:38

2 Answers2

0

Is your function actually called:

stoff_stueckgewicht(id bigint)

Or perhaps:

stoff_stückgewicht(id bigint)

?

The latter is a likely cause of problems if your locale settings are different between debian and PostgreSQL.

Alternatively, go through all the functions in all of the schemas on your database, using pgAdmin III and find the function manually.

Patrick
  • 29,357
  • 6
  • 62
  • 90
  • I renamed the function to avoid to make the explanation for my issue more understandable and forgot that part. sry. – Kody Mar 21 '16 at 12:37
0

Use this to diagnose your problem:

SELECT n.nspname AS schema, p.proname AS function
     , pg_get_function_identity_arguments(p.oid) As args
FROM   pg_proc p
JOIN   pg_namespace n ON n.oid = p.pronamespace
WHERE  p.proname LIKE 'calculate%';

And check your search_path:

Either way, a bigint function can be called with a numeric literal - defaulting to integer, but there is a registered cast to bigint.

Consider Function Type Resolution:

Community
  • 1
  • 1
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228