Hi, I just started playing around with function an...
# sql
t
Hi, I just started playing around with function and triggers... I created a trigger and function that copies new users to a 'profiles' table. I started looking at encrypting data with pgp_sym_encrypt (again, just to see what's possible). It works in other functions, but I can't seem to make it work here when a user signs up. create or replace function public.handle_new_user() returns trigger as $$ begin insert into public.profiles (id, username) values (new.id, pgp_sym_encrypt(new.email, 'some_key')); return new; end; $$ language plpgsql security definer; This is the error message in the logs: (SQLSTATE 25P02): ERROR: function pgp_sym_encrypt(text, text) does not exist (SQLSTATE 42883)"
s
It's strange that it works in other functions, but not in this one. Here's a few things worth checking and trying: - Make sure the pg_crypto extension is enabled (should be if it works elsewhere) - Try using
extensions.pgp_sym_encrypt
instead - clarifying the schema it's located in sometimes helps, especially if
extensions
schema isn't on your search path - Make sure that your
username
column is type
bytea
(that's the type returned from the function) - the error shown shouldn't be the one here, but I'd check just in case
t
@User , what a legend, thanks! Adding the schema worked! thanks so much.