Thread: Usernames with hyphens

Usernames with hyphens

From
Devrim GUNDUZ
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi,

AFAIK, PostgreSQL does not allow hyphens in usernames and databases, 
right?

template1=# SELECT version();                                                   version
- --------------------------------------------------------------------------------------------------------------
PostgreSQL8.0.3 on i686-redhat-linux-gnu, compiled by GCC gcc (GCC) 
 
3.2.3 20030502 (Red Hat Linux 3.2.3-42)
(1 row)

template1=# CREATE DATABASE hyphen-test;
ERROR:  syntax error at or near "-" at character 22
LINE 1: CREATE DATABASE hyphen-test;                             ^
This is the same for users;

template1=# CREATE USER hyphen-test;
ERROR:  syntax error at or near "-" at character 18
LINE 1: CREATE USER hyphen-test;                         ^
However, createuser allows us to create users that include a hyphen:

# createuser hyphen-test -U postgres
Shall the new user be allowed to create databases? (y/n) n
Shall the new user be allowed to create more new users? (y/n) n
Password:
CREATE USER

but it is not allowed in CREATE DATABASE syntax:

template1=# CREATE DATABASE hyphen_test with owner hyphen-test;
ERROR:  syntax error at or near "-" at character 46
LINE 1: CREATE DATABASE hyphen_test with owner hyphen-test;


template1=# SELECT * from pg_shadow WHERE usename='hyphen-test';   usename   | usesysid | usecreatedb | usesuper |
usecatupd| passwd | 
 
valuntil | useconfig
- -------------+----------+-------------+----------+-----------+--------+----------+----------- hyphen-test |      103
|f           | f        | f         |        | 
 
|
(1 row)

Is it a bug in createuser or am I missing a point? Same applies to 
createdb:

# createdb hyphen-test -U postgres
Password:
CREATE DATABASE

Regards,

- --
Devrim GUNDUZ
devrim~gunduz.org, devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.tdmsoft.com.tr                      http://www.gunduz.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFCrW5dtl86P3SPfQ4RAuF5AJ4xGGqswtNdzcLGi/lNCo8hD5PsYgCggllm
u5GYDj/JODlZ5HA+XYD79DM=
=pFsg
-----END PGP SIGNATURE-----


Re: Usernames with hyphens

From
"Weilguni Mario"
Date:
In fakt, it allows users with hyphens, but you have to use quotes:
CREATE USER "foo-bar";
DROP USER "foo-bar";

Regards,Mario Weilguni

-----Ursprüngliche Nachricht-----
Von: pgsql-hackers-owner@postgresql.org [mailto:pgsql-hackers-owner@postgresql.org] Im Auftrag von Devrim GUNDUZ
Gesendet: Montag, 13. Juni 2005 13:31
An: pgsql-hackers@postgresql.org
Betreff: [HACKERS] Usernames with hyphens

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi,

AFAIK, PostgreSQL does not allow hyphens in usernames and databases, right?

template1=# SELECT version();                                                   version
- --------------------------------------------------------------------------------------------------------------
PostgreSQL8.0.3 on i686-redhat-linux-gnu, compiled by GCC gcc (GCC) 
3.2.3 20030502 (Red Hat Linux 3.2.3-42)
(1 row)

template1=# CREATE DATABASE hyphen-test;
ERROR:  syntax error at or near "-" at character 22 LINE 1: CREATE DATABASE hyphen-test;                             ^
This is the same for users;

template1=# CREATE USER hyphen-test;
ERROR:  syntax error at or near "-" at character 18 LINE 1: CREATE USER hyphen-test;                         ^
However, createuser allows us to create users that include a hyphen:

# createuser hyphen-test -U postgres
Shall the new user be allowed to create databases? (y/n) n Shall the new user be allowed to create more new users?
(y/n)n 
Password:
CREATE USER

but it is not allowed in CREATE DATABASE syntax:

template1=# CREATE DATABASE hyphen_test with owner hyphen-test;
ERROR:  syntax error at or near "-" at character 46 LINE 1: CREATE DATABASE hyphen_test with owner hyphen-test;


template1=# SELECT * from pg_shadow WHERE usename='hyphen-test';   usename   | usesysid | usecreatedb | usesuper |
usecatupd| passwd |  
valuntil | useconfig
- -------------+----------+-------------+----------+-----------+--------+----------+----------- hyphen-test |      103
|f           | f        | f         |        |  
|
(1 row)

Is it a bug in createuser or am I missing a point? Same applies to
createdb:

# createdb hyphen-test -U postgres
Password:
CREATE DATABASE

Regards,

- --
Devrim GUNDUZ
devrim~gunduz.org, devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.tdmsoft.com.tr                      http://www.gunduz.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFCrW5dtl86P3SPfQ4RAuF5AJ4xGGqswtNdzcLGi/lNCo8hD5PsYgCggllm
u5GYDj/JODlZ5HA+XYD79DM=
=pFsg
-----END PGP SIGNATURE-----

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Re: Usernames with hyphens

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org] On Behalf Of Devrim GUNDUZ
> Sent: 13 June 2005 12:31
> To: pgsql-hackers@postgresql.org
> Subject: [HACKERS] Usernames with hyphens
>
> template1=# CREATE USER hyphen-test;
> ERROR:  syntax error at or near "-" at character 18
> LINE 1: CREATE USER hyphen-test;
>

Hi Devrim,

Try:

CREATE USER "hyphen-test";

Regards, Dave


Re: Usernames with hyphens

From
Michael Glaesemann
Date:
On Jun 13, 2005, at 8:30 PM, Devrim GUNDUZ wrote:

> AFAIK, PostgreSQL does not allow hyphens in usernames and  
> databases, right?

AFAIK, you can use whatever you want if you double-quote it.

test=# create database "hyphen-test";
LOG:  transaction ID wrap limit is 2147484134, limited by database  
"test"
CREATE DATABASE
test=# \c hyphen-test
You are now connected to database "hyphen-test".

Note that this is the SQL command, rather than another command such  
as the createdb or createuser client apps or psql. For example, \c  
works without the quotes.

Michael Glaesemann
grzm myrealbox com




Re: Usernames with hyphens

From
Devrim GUNDUZ
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi,

On Mon, 13 Jun 2005, Weilguni Mario wrote:

> In fakt, it allows users with hyphens, but you have to use quotes:
> CREATE USER "foo-bar";
> DROP USER "foo-bar";

Yeah quotes. I should have remembered it. Thanks Weilgunu, Dave and 
Michael.

Regards,
- --
Devrim GUNDUZ
devrim~gunduz.org, devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.tdmsoft.com.tr                      http://www.gunduz.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFCrXLftl86P3SPfQ4RAhCaAKC2xws9QRhsk8zP4U85c1GXRRZfiACfbrSC
tUWfWE7Ve3NfBCjEf6n+x8U=
=Ds6t
-----END PGP SIGNATURE-----