Postgres names are surprisingly flexible
SELECT * FROM ๐ฑ
As long as the Postgres server uses UTF-8 as its encoding, you can create a table with emojis as the name.
CREATE TABLE ๐ฉ๐๐ค (
id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name TEXT NOT NULL
);
INSERT INTO ๐ฉ๐๐ค (name) VALUES ('poop');
-- INSERT 0 1
SELECT * FROM ๐ฉ๐๐ค;
/*
id | name
----+------
1 | poop
(1 row)
*/
Notice that you don't need to quote the emoji name. Given that there's no case-folding with emojis, emojis are superior to uppercase letters in table names in this one respect.
There are surprisingly few restrictions to what you can name your tables:
- Quoted identifiers can contain any character, including spaces and punctuation.
- The length of an identifier is restricted to
NAMEDATALEN
- 1 bytes.NAMEDATALEN
is 63 by default, but can be set at compile time.
All of these are valid identifiers, which means you can use them as table names:
" "
"This is a valid identifier!!"
่กจๅ
"..."
"SELECT"
Identifiers don't need to be quoted if they "begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_)."
All the above rules apply to all identifiers, including column names, index names, and constraint names:
ALTER TABLE ๐ฉ๐๐ค
ADD CONSTRAINT "๐ซ empty names! ๐ค" CHECK (length(name) > 0);
-- This adds a constraint named "๐ซ empty names! ๐ค" to the ๐ฉ๐๐ค table.
Please don't do this. However if you choose to do this, please tell me all about it.
See https://www.postgresql.org/docs/current/sql-syntax-lexical.html for more details.
Like this article? Follow me on Bluesky or subscribe to the RSS feed to get notified about new articles.