Skip to content

Syntax error when using non-standard DB names #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mksplg opened this issue Dec 15, 2017 · 8 comments
Closed

Syntax error when using non-standard DB names #5

mksplg opened this issue Dec 15, 2017 · 8 comments

Comments

@mksplg
Copy link

mksplg commented Dec 15, 2017

When using a non standard DB name, e.g. test-db, a syntax error is thrown.

db_1  | Multiple database creation requested: test-db
db_1  |   Creating user and database 'test-db'
db_1  | 2017-12-15 09:11:35.898 UTC [66] ERROR:  syntax error at or near "-" at character 17
db_1  | 2017-12-15 09:11:35.898 UTC [66] STATEMENT:  CREATE USER test-db;
db_1  | ERROR:  syntax error at or near "-"
db_1  | LINE 1: CREATE USER test-db;

This could be avoided by using double quotes around the variables in the SQL statements.

@mrts
Copy link
Owner

mrts commented Dec 15, 2017

Agreed. Would you perhaps like to send a pull request :)?

@mrts
Copy link
Owner

mrts commented Dec 15, 2017

I'm sorry, but after further investigation I suggest that we don't do this - it forces everyone to use quotes throughout, see e.g. https://stackoverflow.com/a/6331658/258772. This is not a good thing.

What do you think?

@mrts mrts added the wontfix label Dec 15, 2017
@mksplg
Copy link
Author

mksplg commented Dec 15, 2017

A quick test didn't show the problem described in the SO answer.

psql (10.1, server 9.6.1)
Type "help" for help.

postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | =Tc/postgres         +
           |          |          |         |       | postgres=CTc/postgres+
           |          |          |         |       | user=CTc/postgres
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
(3 rows)

postgres=# CREATE DATABASE "test";
CREATE DATABASE
postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | =Tc/postgres         +
           |          |          |         |       | postgres=CTc/postgres+
           |          |          |         |       | user=CTc/postgres
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 test      | postgres | UTF8     | C       | C     |
(4 rows)

postgres=# ALTER DATABASE test RENAME TO test2;
ALTER DATABASE
postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | =Tc/postgres         +
           |          |          |         |       | postgres=CTc/postgres+
           |          |          |         |       | user=CTc/postgres
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 test2     | postgres | UTF8     | C       | C     |
(4 rows)

postgres=#
psql (10.1, server 9.6.1)
Type "help" for help.

postgres=# CREATE TABLE A();
CREATE TABLE
postgres=# \dt
        List of relations
 Schema | Name | Type  |  Owner
--------+------+-------+----------
 public | a    | table | postgres
(1 row)

postgres=# SELECT * FROM A;
--
(0 rows)

postgres=# SELECT * FROM "A";
ERROR:  relation "A" does not exist
LINE 1: SELECT * FROM "A";
                      ^
postgres=# SELECT * FROM "a";
--
(0 rows)

postgres=# #

I think the problem is that postgresql converts names without quotes to lowercase, so using quotes might be unexpected for the user. I don't really know enough about postgres to say if this has further implications.

@mksplg
Copy link
Author

mksplg commented Dec 15, 2017

Adding quotes around the names in docker-compose actually works for me, looks like they are passed to the script.

[...]
    environment:
      - POSTGRES_MULTIPLE_DATABASES="test-db-1","test-db-2"
[...]

@mrts
Copy link
Owner

mrts commented Dec 16, 2017

Perfect, now you hit the mark 👍 - it's a documentation issue after all. I'll amend the readme accordingly.

@mrts
Copy link
Owner

mrts commented Dec 16, 2017

And many thanks for the thorough tests, much appreciated!

@mrts mrts removed the wontfix label Dec 16, 2017
@mrts
Copy link
Owner

mrts commented Dec 16, 2017

Please review #7, do you agree this is sufficient?

@mrts
Copy link
Owner

mrts commented Dec 16, 2017

Fixed with #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants