Created
December 18, 2022 09:24
-
-
Save thalesbruno/9c94ce752b29f0eed954ceca41aadefd to your computer and use it in GitHub Desktop.
Revisions
-
thalesbruno created this gist
Dec 18, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ # PostgreSQL Basic Guide ## Primary Keys Autoincrement numeric id ```sql CREATE TABLE users ( id SERIAL PRIMARY KEY ); ``` Autogenerated UUID id ```sql CREATE TABLE products ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY ); ``` ## ENUM type Create an ENUM type ```sql CREATE TYPE order_status AS ENUM ('open', 'pending', 'closed', 'canceled'); ``` Use created type ```sql CREATE TABLE order ( id SERIAL PRIMARY KEY, status order_status ); ```