New to postgresql. It might be very simple; but am not getting it.
I've this in mysql:
insert into APP_USERS VALUES
(1, 'admin', 'adminemailid','', 'System', 'Administrator', 'SysAdmin', 'CompanyName',
sha('password123'), 'ADMIN', 2,'SCREEN',0);
After referring postgresql documentations on password encryption/hashing and various similar questions on Stackoverflow;
I tried it's equivalent in postgresql as:
insert into APP_USERS VALUES
(1, 'admin', 'adminemailid','', 'System', 'Administrator', 'SysAdmin', 'CompanyName',
crypt('password123',gen_salt('sha1')), 'ADMIN', 2,'SCREEN',0)
But; it throws me an error at function gen_salt()
:
No function matches the given name and argument types. You might need to add explicit type casts.
(The datatype of column(field) password is character varying.)
I read various manuals on type casting in postgresql and tried casting the function.
But; no use. I came across various similar errors.
Can I know what exactly am missing? or what is the exact way of type casting? Or do I need to add chkpass module (extension) for this?
I already have pgcrypto extension and am using postgresql 9.6.
It is not the answer actually but a brief explanation how to find the source of the error.
First of all lets find the
pgcrypto
extension:It should return something like:
So the
pgcrypto
installed in the schemand
in the my database.Next lets look to the
search_path
parameter which provide the information where to search DB objects:It means that the objects will be searched in the schema with name of the current user and, if nothing found, in the schema
public
.Finally lets check the current user:
So as you can see the extension installed in the schema
nd
can not be found using thesearch_path
which actually ispostgres, public
and we got the error:There are several ways how to fix it depending of the actual values for your DB mentioned above.
You can move the extension to another schema like:
You can change the
search_path
option like:Finally you could to explicitly specify the schema in the SQL statement: