Encrypt password in insert statement in postgresql throws an error (Need to add explicit type cast)
<p>New to postgresql. It might be very simple; but am not getting it.</p>

<p>I've this in mysql:</p>

<pre><code>insert into APP_USERS VALUES
(1, 'admin', 'adminemailid','', 'System', 'Administrator', 'SysAdmin', 'CompanyName',
sha('password123'), 'ADMIN', 2,'SCREEN',0);
</code></pre>

<p>After referring postgresql documentations on password encryption/hashing and various similar questions on Stackoverflow;</p>

<p>I tried it's equivalent in postgresql as:</p>

<pre><code>insert into APP_USERS VALUES
(1, 'admin', 'adminemailid','', 'System', 'Administrator', 'SysAdmin', 'CompanyName',
crypt('password123',gen_salt('sha1')), 'ADMIN', 2,'SCREEN',0)
</code></pre>

<p>But; it throws me an error at function <code>gen_salt()</code>:</p>

<p><strong>No function matches the given name and argument types. You might need to add explicit type casts.</strong></p>

<p>(The datatype of column(field) password is <strong>character varying</strong>.)</p>

<p>I read various manuals on type casting in postgresql and tried casting the function.</p>

<p>But; no use. I came across various similar errors.</p>

<p>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?</p>

<p>I already have pgcrypto extension and am using postgresql 9.6.</p>