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

Поиск
Список
Период
Сортировка
Искать

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

От:
Alexander 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

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

От:
Guillaume Lelarge <guillaume@lelarge.info>
Дата:
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

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

От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
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 :
> 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
>

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

От:
"A. Kretschmer" <andreas.kretschmer@schollglas.com>
Дата:
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

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

От:
Alexander Farber <alexander.farber@gmail.com>
Дата:
And identifiers means column names (eventually containing whitespace)?

Thank you
Alex

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

От:
"A. Kretschmer" <andreas.kretschmer@schollglas.com>
Дата:
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

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

От:
Thom Brown <thombrown@gmail.com>
Дата:
On 23 June 2010 10:41, Alexander Farber  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

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

От:
Bruce Momjian <bruce@momjian.us>
Дата:
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          http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

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