CREATE TABLE test (
id uuid PRIMARY KEY NOT NULL DEFAULT get_random_uuid(),
title text NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS test_title_key ON test (title);
SELECT count(*) AS total, COALESCE(name, 'no name') FROM user WHERE id IN (100, 101) GROUP BY group;-
All keywords (SELECT, INSER, etc.) must be in upper case;
-
All identifiers (table, column, indexes, etc. names) must be in the snake_case.
- Reserved row identifiers
NEW,OLD,EXCLUDEDmust be unquoted upper case.
- Reserved row identifiers
-
Subquery expressions:
EXISTS,IN,NOT IN,ANY,SOME,ALLmust be in upper case. -
Conditional expressions
CASE,COALECSE,NULLIF,CREATEST,LEASTmust be in upper case; -
All type names must be in the
snake_case. -
All functions names must be in the
snake_case.
Indexes must be unique across the schema.
Index name must be in the snake_case.
Index name template <table_name>_<column_name>..._<suffix>, where the suffix is one of the following:
- 'pkey' for a Primary Key constraint;
keyfor a Unique constraint;exclfor an Exclusion constraint;idxfor any other kind of index;fkeyfor a Foreign key;checkfor a Check constraint;
Examples
CREATE INDEX user_id_idx ON "user" ( id );
CREATE INDEX user_id_title_idx ON "user" ( id, title );Sequence name template <table_name>_<column_name>_seq.
Examples
CREATE SEQUENCE user_id_seq AS int8;PostgreSQL triggers are unique across the table, so trigger name can be: [<column_name>...]_<triger_event>, eg: before_update, some_column_after_insert;
SQLite triggers are global, so name must be fully specified, template <table_name>_[<column_name>...]_<triger_event>_trigger.
Trigger functions names must have same name as trigger and must have _trigger suffix.
Examples:
CREATE FUNCTION user_before_insert_trigger() RETURNS TRIGGER
-- SQLite
CREATE TRIGGER user_before_insert_trigger BEFORE INSERT ON user FOR EACH ROW EXECUTE PROCEDURE user_before_insert_trigger();
-- PostgreSQL
CREATE TRIGGER before_insert BEFORE INSERT ON user FOR EACH ROW EXECUTE PROCEDURE user_before_insert_trigger();