skip to Main Content

I created a new age_date() function using the following SQL and C code:

SQL:

CREATE FUNCTION ag_catalog.age_date()
RETURNS cstring
LANGUAGE c
STABLE
PARALLEL SAFE
AS 'MODULE_PATHNAME';

C Code:

Datum age_date(PG_FUNCTION_ARGS) {
  // Program Logic
}

After stopping and restarting the server, I attempted to run this function within a cypher query. However, I encountered an error stating that the function does not exist.

5

Answers


  1. Try make distclean on age and then re-install it. After that load it again in postgres and try again

    Login or Signup to reply.
  2. When modifying the C code, the changes will take effect immediately upon restarting the server. However, when altering the SQL file, a server restart is required, along with dropping and recreating the extension.

    Execute the following commands:

    • DROP EXTENSION age;

      Restart the server

    • CREATE EXTENSION age;

    • LOAD ‘age’;

    • SET search_path TO ag_catalog;

    I hope this resolves the issue.

    Login or Signup to reply.
  3. You have to run make install again after changing anything in the repo like adding or modifying functions for them to take effect.

    Further you should run install check as well to see if it breaks anything.

    Then as pointed out in other answers, you have to drop the extension and reload it.

    Hope this helps!

    Login or Signup to reply.
  4. It could be a number of reasons.

    Did you compile and reinstalled the extension?

    It could be that you forgotten the function registration above the function:

    PG_FUNCTION_INFO_V1(age_date);
    
    Datum age_date(PG_FUNCTION_ARGS) {
      // Program Logic
    }
    

    Either that, or you may be calling the function wrongly, which should be

    SELECT ag_catalog.age_date;
    -- or
    SELECT ag_catalog.age_date();
    

    Also, you may need to drop extension and creating it again if you altered the .sql file.

    Please add more details so we can help you more assertively.

    Login or Signup to reply.
  5. If you are writing function in new "C" file then you need to modify "MAKEFILE" as well.

    Here is what to do:

    #add the folloing line to the OBJS 
    src/path/to/file/new_file_name.o 
    

    Next, "clean" & "install" it again:

    sudo make clean PG_CONFIG=/usr/local/pgsql/bin/pg_config
    make PG_CONFIG=/usr/local/pgsql/bin/pg_config
    make install PG_CONFIG=/usr/local/pgsql/bin/pg_config
    

    Reference: https://dev.to/rrrokhtar/guide-to-age-contribution-and-modifying-the-source-code-to-add-new-functions-l7m

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search