Skip to content

Instantly share code, notes, and snippets.

@kovid-rathee
kovid-rathee / array_by_index_postgresql.sql
Last active February 24, 2019 09:29
Getting an array element by Index
create table array_fn (test_array text[]);
insert into array_fn values ('{This,Is,What,Bothers,Me}');
select test_array[3]::varchar from array_fn;
@kovid-rathee
kovid-rathee / unnest_array_in_postgresql.sql
Created February 24, 2019 09:34
Unnest array in PostgreSQL
select name,
unnest(schedule),
unnest(pay_by_quarter)
from sal_emp;
@kovid-rathee
kovid-rathee / transformation_example_1.sql
Last active February 25, 2019 09:16
Sample transformation #1
create type order_status as enum (
'placed',
'accepted',
'cancelled_by_customer',
'cancelled_by_restaurant',
'delivered'
);
drop table if exists orders;
create table orders (
@kovid-rathee
kovid-rathee / master-slave-mysql-scratch.sql
Created July 13, 2019 07:31
Setting up MySQL Replication from Scratch on two instances of MySQL Server
# Run on Master
# Replace slave-ip and master-ip with actual ip addresses of those machines
CREATE USER repl;
GRANT REPLICATION SLAVE ON *.* TO repl_user@'slave-ip' IDENTIFIED BY 'passwd';
# Run on Slave
CHANGE MASTER TO MASTER_HOST = 'master-ip', MASTER_PORT = 3306, MASTER_USER = 'repl', MASTER_PASSWORD = 'passwd';
START SLAVE;
# To check the Status of Replication