· 6 years ago · Jun 02, 2019, 09:22 AM
1/*
2***********************************************
3
4 psql -h hostname -U user_name db_name
5
6 psql -E: Describe the underlaying queries of the \ commands
7 psql -l: List all database and exit
8
9 \q: Quit
10 \c db_name: Switch database
11 \l: Show databases
12 \d table_name: Show table info
13 \d+: Show extended table info
14 \x: Toggle expanded display
15***********************************************
16*/
17
18-- Generate a million rows of random data
19SELECT md5(random()::text), md5(random()::text) FROM
20 (SELECT * FROM generate_series(1,1000000) AS id) AS x;
21
22-- Create GIN index over
23CREATE EXTENSION IF NOT EXISTS pg_trgm;
24CREATE INDEX lol_idx ON table_name USING gin (col_1 gin_trgm_ops, col_2 gin_trgm_ops);
25-- gin_trgm_ops: Index using trigrams over selected columns. A trigram is a DS that hold 3 letters of a word. Essentially, Postgres will break down each text column down into trigrams and use that in the index when we search against it.
26-- Caveat: Input query must be at least 3 letters, as Postgres will need to be able to extract at least one trigram from the input query in order to use our trigram index.