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

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

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

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.

Thank you
Alex

PS: Using postgresql-server-8.3.6 @ OpenBSD 4.5

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|

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

Guillaume Lelarge-3
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

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|

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

Pavel Stehule
In reply to this post by Alexander Farber
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 <[hidden email]>:

> 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 ([hidden email])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|

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

A. Kretschmer
In reply to this post by Alexander Farber
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

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|

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

Alexander Farber
And identifiers means column names (eventually containing whitespace)?

Thank you
Alex

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|

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

A. Kretschmer
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

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|

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

Thom Brown
In reply to this post by Alexander Farber
On 23 June 2010 10:41, Alexander Farber <[hidden email]> 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

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|

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

Bruce Momjian
In reply to this post by A. Kretschmer
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  <[hidden email]>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

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

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