简体   繁体   中英

HugSQL defined function not found

This will probably be very thin but I am running out of options...

I am using clojure with hugsql and I am a true beginner with database tech. I am trying to call an user-defined function that a colleague has defined in the database.

So, my problem is: making the query in databases software such as dbeaver, I get the results with no issues, however running from hugsql I get an error claiming it does not recognize the function.

My.sql file is something like

-- :name a-fake-name :? :1
-- :doc some fake documentation

select * from a_fake_user_defined_function(:arg1, :arg2, :arg3, :arg4, 1); 

I read the queries like so

(ns sql.commands
  (:require [hugsql.core :as hugsql]))

(hugsql/def-db-fns "sql/file.sql")

I runned the command from clojure:

(def db
  {:classname "org.postgresql.Driver"
   :subprotocol "postgresql"
   :subname subname
   :user user
   :password password})

(sql/a-fake-name db {:arg1 "first-argument" :arg2 "second-one" :arg3 "third" :arg4 "and-forth"})

And the error I get is

ERROR: function a_fake_user_defined_function(character varying,
   character varying, character varying, character varying, integer)
   does not exist Hint: No function matches the given name and
   argument types. You might need to add explicit type casts.
   Position: 15

From the error I assume, I am missing some notation or configuration... Does anyone have an idea on what I can do?

I tried to look on hugsql documentation but got no luck.

Thx!

PS.: I am well aware it is a good practice provide an reproducible error on stackoverflow, but this is from my work I am quite clueless on how to reproduce the database. Hopefully this is enough...

As hinted by @cfrick, the problem was with the arguments definition in the hugsql file. The answer was also provided by a contributor in a github issue .

The problem was that it was not finding a function with that name and those type of arguments. The solution then was to type cast with double-colon each of the arguments ( https://www.hugsql.org/#colon ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM