Single quotes vs. double quotes when setting a pwd and other cmds

Started by Alexander Farberalmost 16 years ago8 messagesgeneral
Jump to latest
#1Alexander Farber
alexander.farber@gmail.com

Hello,

why aren't double quotes accepted below?

db1=# alter user user1 password "pass1";
ERROR: syntax error at or near ""pass1""
LINE 1: alter user user1 password "pass1";
^
db1=# alter user user1 password 'pass1';
ALTER ROLE

Is there a thumb rule to know when to use which quotes?
I'm often confused by them when using psql.

Thank you
Alex

PS: Using postgresql-server-8.3.6 @ OpenBSD 4.5

#2Guillaume Lelarge
guillaume@lelarge.info
In reply to: Alexander Farber (#1)
Re: Single quotes vs. double quotes when setting a pwd and other cmds

Le 23/06/2010 11:03, Alexander Farber a �crit :

Hello,

why aren't double quotes accepted below?

db1=# alter user user1 password "pass1";
ERROR: syntax error at or near ""pass1""
LINE 1: alter user user1 password "pass1";
^
db1=# alter user user1 password 'pass1';
ALTER ROLE

Is there a thumb rule to know when to use which quotes?
I'm often confused by them when using psql.

Use double quotes for identifiers, and single quotes for string values.

The password is a string, so you use single quotes with it. The username
is an identifier, so you (can) use double quotes with it.

--
Guillaume
http://www.postgresql.fr
http://dalibo.com

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alexander Farber (#1)
Re: Single quotes vs. double quotes when setting a pwd and other cmds

Hello

ANSI SQL uses double quotes only for SQL identifiers. For literals are
used single quotes.

like

SELECT col AS "some strange sql column identifier", 'some string
value' FROM "some strange sql table identifier"

so for case sensitive or strange (is keyword, contains space) sql
identifiers use double quotes, for string constants use single quotes.

some other database uses [] or ` .

Regards
Pavel

2010/6/23 Alexander Farber <alexander.farber@gmail.com>:

Show quoted text

Hello,

why aren't double quotes accepted below?

db1=# alter user user1 password "pass1";
ERROR:  syntax error at or near ""pass1""
LINE 1: alter user user1 password "pass1";
                                ^
db1=# alter user user1 password 'pass1';
ALTER ROLE

Is there a thumb rule to know when to use which quotes?
I'm often confused by them when using psql.

Thank you
Alex

PS: Using postgresql-server-8.3.6 @ OpenBSD 4.5

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4A. Kretschmer
andreas.kretschmer@schollglas.com
In reply to: Alexander Farber (#1)
Re: Single quotes vs. double quotes when setting a pwd and other cmds

In response to Alexander Farber :

Hello,

why aren't double quotes accepted below?

db1=# alter user user1 password "pass1";
ERROR: syntax error at or near ""pass1""
LINE 1: alter user user1 password "pass1";
^
db1=# alter user user1 password 'pass1';
ALTER ROLE

Is there a thumb rule to know when to use which quotes?
I'm often confused by them when using psql.

Use ' for variable strings (values), and " for identifier (table-name,
column-name).

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99

#5Alexander Farber
alexander.farber@gmail.com
In reply to: A. Kretschmer (#4)
Re: Single quotes vs. double quotes when setting a pwd and other cmds

And identifiers means column names (eventually containing whitespace)?

Thank you
Alex

#6A. Kretschmer
andreas.kretschmer@schollglas.com
In reply to: Alexander Farber (#5)
Re: Single quotes vs. double quotes when setting a pwd and other cmds

In response to Alexander Farber :

And identifiers means column names (eventually containing whitespace)?

Right.

test=# select 'foo' as "my new column";
my new column
---------------
foo
(1 row)

Regards, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99

#7Thom Brown
thombrown@gmail.com
In reply to: Alexander Farber (#5)
Re: Single quotes vs. double quotes when setting a pwd and other cmds

On 23 June 2010 10:41, Alexander Farber <alexander.farber@gmail.com> wrote:

And identifiers means column names (eventually containing whitespace)?

Columns, tables, schemas, views, triggers, indexes etc. See:
http://www.postgresql.org/docs/8.4/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Regards

Thom

#8Bruce Momjian
bruce@momjian.us
In reply to: A. Kretschmer (#6)
Re: Single quotes vs. double quotes when setting a pwd and other cmds

A. Kretschmer wrote:

In response to Alexander Farber :

And identifiers means column names (eventually containing whitespace)?

Right.

test=# select 'foo' as "my new column";
my new column
---------------
foo
(1 row)

And double-quotes preserve case:

test=> select 'foo' as Mine;
mine
------
foo
(1 row)

test=> select 'foo' as "Mine"; <-- double-quotes
Mine <--
------
foo
(1 row)

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ None of us is going to be here forever. +