Not using a hyphen in yaml key value for Travis

trying to do this as specified here: Setting up Databases and Services - Travis CI

  - bundle exec rake lint
  - "psql -c 'create database authentication-server_test;' -U postgres"

language: ruby

  - postgresql

Travis throws with:

$ psql -c 'create database authentication-server_test;' -U postgres
ERROR:  syntax error at or near "-"
LINE 1: create database authentication-server_test;

any idea? this has to do with the key value pair any fix for this?

Your problem is that this PostgreSQL identifier, not a key value pair:


The above needs quotes to be quoted so that PostgreSQL won’t try to interpret the - as an operator. Other wise, the latter will happen. Identifiers are quoted with double quotes so you need to this:


Into the database. You could escape the double quotes in your .travis.yml:

  - bundle exec rake lint
  - "psql -c 'create database \"authentication-server_test\";' -U postgres"

Drop the outer double quotes (the YAML quotes for the string) while adding the inner double quotes (for the PostgreSQL identifier):

  - bundle exec rake lint
  - psql -c 'create database "authentication-server_test";' -U postgres

Alternatively you can switch to createdb about avoid the problem altogether:

  - bundle exec rake lint
  - createdb authentication-server_test -U postgres

So as you can see its’ not a key value pair problem it’s only having to worry about the shell’s and YAML’s quoting needs (neither of which apply here).

1 Like