Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How to assign a parameter/argument in postgres psql UPDATE command. I tried with the following command.

c="openssl rand -base64 6"
ab=eval $c
psql -d db_name -c "UPDATE table_name SET password = '$ab' WHERE name = 'cde'" 

The above command updates the table 'table_name' in the colum 'password' as ' ' (quotes with empty string)instead of updating the value of '$ab'. The '$ab' is a string.

Could anyone help on this?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

This is the way it works:

c="openssl rand -base64 6"
ab=`$c`
psql -d db_name -c "UPDATE table_name SET password = '$ab' WHERE name = 'cde'" 
share|improve this answer
    
perfectly works. Thanks for your correction. –  user3346016 Feb 25 at 10:05
    
Why don't you just write ab=$( openssl rand -base64 6 ) to start with? –  Craig Ringer Feb 25 at 13:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.