2

I need to create script in linux. There is command like:

psql -U postgres -d ticketon -c "UPDATE "user" SET "password" = 'test'"

When I put it to quotation marks, there is mistake. When out of quotation marks, there also is error. I have tried almost everything, but still without success. Do anyone know what is correct syntax?

3
  • 2
    Another good reason to avoid table (or column) names that need quoting... Commented Jul 9, 2014 at 14:20
  • 2
    Can't test, but I'd try psql -U postgres -d ticketon -c "UPDATE \"user\" SET \"password\" = 'test'" Commented Jul 9, 2014 at 14:21
  • I feel so strongly against needing to put double quotes around names that I couldn't agree more with a_horse_with_no_name. What a sloppy mess to deal with and that's just a simple update statement. Commented Jul 9, 2014 at 14:35

3 Answers 3

6

How a_horse_with_no_name said.

psql -U postgres -d dbName -c "UPDATE \"user\" SET \"password\" = 'test'"
Sign up to request clarification or add additional context in comments.

Comments

0

I was doing something similar recently. What you want to do is preform the logon first (psql -U postgres -d ticketon -c) and then pipe via STDIN the query you wish to preform ("UPDATE "user" SET "password" = 'test'"). In bash this will be the following:

    echo "UPDATE "user" SET "password" = 'test'" | psql -U postgres -d ticketon -c 

The above could work better than just using the -c command for a single command, because postgres does not like dealing with double quotes.

Comments

0

No need for excessive quoting if you use an sh here document:

#!/bin/sh
psql -U postgres -d ticketon <<XXX
UPDATE "user"
SET password = 'test'
WHERE username = 'James' -- I think a where clause is needed here ...
   ;
XXX

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.