Reputation: 4675
I am trying to reset password for all users with following psql command. The command executes successfully but the value of password is wrong. The password is bcrypt string of 12345
psql -U myuser -d mydb -c "update \"Users\" set \"PASSWORD\" = '$2a$10$u0vd9noCisUUJME9k4daU.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW'"
The query:
select "PASSWORD" from "Users";
returns:
a.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW
instead of:
$2a$10$u0vd9noCisUUJME9k4daU.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW
What I understand that postgres is taking $ as a placeholder or special character. How can I escape it?
Upvotes: 2
Views: 1124
Reputation: 17711
The problem is not with postgres but with the shell. It interprets the dollar signs as beginning of variables. You should escape them wit a backslash ('\$2a\$10\$u0vd9noCisUUJME9k4daU.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW'
):
psql -U myuser -d mydb -c "update \"Users\" set \"PASSWORD\" = '\$2a\$10\$u0vd9noCisUUJME9k4daU.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW'"
Upvotes: 3