I create a database with a hyphen in the middle of the name with createdb
. That successfully creates the database, but within the psql
interactive client, I get a syntax error if I try a command like this:
ALTER DATABASE my-database SET SCHEMA = myschema,public;
psql
complains of a syntax error at or near "-"
Is there some documentation for what counts as a valid PostgreSQL database name?
Should I just underscores instead of hyphens?
Switching Databases Most Postgres servers have three databases defined by default: template0 , template1 and postgres . template0 and template1 are skeleton databases that are or can be used by the CREATE DATABASE command. postgres is the default database you will connect to before you have created any other databases.
Use \l or \l+ in psql to show all databases in the current PostgreSQL server. Use the SELECT statement to query data from the pg_database to get all databases.
For the traditional naming convention: Database names must only consist of the letters a to z (both lower and upper case allowed), the numbers 0 to 9 , and the underscore ( _ ) or dash ( - ) symbols. This also means that any non-ASCII database names are not allowed. Database names must always start with a letter.
Open the RDS console and then choose Databases to display a list of your DB instances. Choose the PostgreSQL DB instance name to display its details.
The documentation you asked about is here:
http://www.postgresql.org/docs/current/interactive/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
Most people just stick to lowercase letters, numeric digits, and underscores -- to avoid typing the quotes all the time.
Try putting it in double quotes:
ALTER DATABASE "my-database" SET SCHEMA = myschema,public;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With