Reputation: 1749
I am writing a bash script which has to deal with postgres passwords. Couldn't find any clear reference to know if single and double quotes are allowed in Postgres passwords. Need to know if that is a valid use case to begin with.
Please quote references for your answers.
Upvotes: 2
Views: 2535
Reputation: 109
if you do
create user s password 'my''Pass'
alter user s password 'my''Pass'
single quote characters must be escaped with another single quote
Upvotes: 0
Reputation: 51599
yes, they are valid. ANY character is valid. but some are not reasonable to use. eg you can even use UTF passwords, but I would not use tab, demo:
db=# do $$ begin execute format('create user s password %L ',concat(chr(10),chr(9),'a')); end;$$;
DO
demo of requiring the valid password:
db=# select * from dblink('postgresql://s:[email protected]:5432/t','select now()') as t (t timestamptz);
ERROR: could not establish connection
DETAIL: FATAL: password authentication failed for user "s"
demo of successfull login:
db=# select * from dblink('postgresql://s:'||concat(chr(10),chr(9),'a')||'@1.1.1.1:5432/t','select now()') as t (t timestamptz);
t
-------------------------------
2018-01-08 13:20:45.149144+00
(1 row)
or:
[postgres@1 ~]$ export PGPASSWORD=$(echo -e "\n\ta")
[postgres@1 ~]$ psql -h 1.1.1.1 -p 5432 -U s
Timing is on.
psql (9.5.4)
Type "help" for help.
s=>
but now imagine you have to put password in terminal using a keyboard - how cosy you can use new line and tabulation, entering password?..
thus again - any char is allowed for password, but not all recommended
Upvotes: 3