1

My boss sent me a process, in to which I need to:

  • make a function that creates a temp table
  • grab data from a table
  • use a function to refine the data
  • create a hash code for 2 of the columns
  • insert all the data from the temp to the original data
  • drop the table

I've been trying to look what the make_hash() function does. Whenever I run the FUNCTION it gives me an error on that line, so I'm guessing I need to declare it first before the begin statement in the create function. Or is it a user-created function? If so, is there a way for me to find which schema the function is located?

I've been trying to research in the books and online but I couldn't find anything, even in the PostgreSQL website.

--------------------------------------------

ERROR:  function make_hash(character varying) does not exist
LINE 1: UPDATE temp_match_queue_04022012 SET title_hash = make_hash(...
                                                          ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
QUERY:  UPDATE temp_match_queue_04022012 SET title_hash = make_hash(as_title) WHERE as_title IS NOT NULL
CONTEXT:  PL/pgSQL function "metadata_matching_temp" line 30 at SQL statement

********** Error **********

ERROR: function make_hash(character varying) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Context: PL/pgSQL function "metadata_matching_temp" line 30 at SQL statement
5
  • 2
    Add your code and the error message.. Commented Apr 3, 2012 at 16:45
  • Updated! Sorry, but the query error I posted earlier was a different one. Commented Apr 3, 2012 at 17:16
  • 1
    Look into pgcrypto Commented Apr 3, 2012 at 18:03
  • @JohnV you should post your solution as an answer and accept it, rather than just a comment. Commented Apr 3, 2012 at 21:28
  • I can't yet since it says I'm still new. Will update it definitely! Commented Apr 3, 2012 at 21:49

2 Answers 2

1

As @Clodoaldo mentioned look into pgcrypto (which you would get by installing it to your postgres, on debian its in postgresql-contrib iirc).

Any function you call must be available before the BEGIN section. You can combine functions into packages if you need more than one.

Sign up to request clarification or add additional context in comments.

4 Comments

I'll take note of this. Thanks Angelo! I'll read more in to the pgcrypto link Clodoaldo sent me.
Ah, and what do you mean by having the function available before the begin section??
@JohnV I meant that before your code is called (isn't it a function itself? I thought so.) the function must already be known to the server.
I believe so. But how I made it work was i needed to type in the schemaname.make_hash() inside the function I created.
1

Nevermind! The make_hash function was written psql that's why it wasn't working properly. I'm using pgAdmin III and the schema name had to be called together with the function for it to work. Thanks a bunch for the help though!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.