'postgresql 13 gen_salt not a function
I am using postgresql v13.2 andlooking to replace importing the bcrypt package with using pgcrypto and 'bf'alogithm.
The attached is using pgAdmin
I get the error ERROR: function gen_salt(unknown) does not exist
The installed pgcrypto version is 1.3
Test table:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
);
Example code:
INSERT INTO users (email, password) VALUES (
'[email protected]',
crypt('johnspassword', gen_salt('bf'))
);
Error message: ERROR: function gen_salt(unknown) does not exist LINE 3: crypt('johnspassword', gen_salt('bf')) ); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 95
Solution 1:[1]
You have to enqable the crypto function
CREATE TABLE users ( id SERIAL PRIMARY KEY, email TEXT NOT NULL UNIQUE, password TEXT NOT NULL );
INSERT INTO users (email, password) VALUES ( '[email protected]', crypt('johnspassword', gen_salt('bf')) );ERROR: function gen_salt(unknown) does not exist
LINE 3: crypt('johnspassword', gen_salt('bf'))
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Run this for every database, you use crypto functions
CREATE EXTENSION pgcrypto;
INSERT INTO users (email, password) VALUES ( '[email protected]', crypt('johnspassword', gen_salt('bf')) );
1 rows affected
db<>fiddle here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | nbk |
