Skip to content

Instantly share code, notes, and snippets.

View rakeshsingh's full-sized avatar

Rakesh Singh rakeshsingh

  • Amazon
  • Seattle, WA
View GitHub Profile
@rakeshsingh
rakeshsingh / amazon-redshift-show-table-ddl.sql
Created May 29, 2015 19:31
Amazon Redshift Show Table DDL
SELECT DISTINCT n.nspname AS schemaname
,c.relname AS tablename
,a.attname AS COLUMN
,a.attnum AS column_position
,pg_catalog.format_type(a.atttypid, a.atttypmod) AS TYPE
,pg_catalog.format_encoding(a.attencodingtype) AS encoding
,a.attisdistkey AS distkey
,a.attsortkeyord AS sortkey
,a.attnotnull AS notnull
,a.attencodingtype AS compression
@rakeshsingh
rakeshsingh / generate-redshift-ddl-for-oracle-table.sql
Last active November 5, 2021 16:05
Generate Redshift Table DDL for Oracle table
WITH COLUMN_DEFINITION AS (
SELECT
TABLE_NAME,
COLUMN_NAME,
CASE
WHEN (DATA_TYPE= 'NUMBER' AND DATA_SCALE = 0 AND DATA_PRECISION <= 9) THEN 'INTEGER'
WHEN (DATA_TYPE= 'NUMBER' AND DATA_SCALE = 0 AND DATA_PRECISION <= 18) THEN 'BIGINT'
WHEN (DATA_TYPE= 'NUMBER' AND DATA_SCALE = 0 AND DATA_PRECISION >= 19) THEN 'DECIMAL(' || DATA_PRECISION || ',0)'
WHEN (DATA_TYPE= 'NUMBER' AND DATA_SCALE > 0) THEN 'DECIMAL(' || DATA_PRECISION || ',' || DATA_SCALE ||')'
WHEN (DATA_TYPE= 'NUMBER' AND nvl(DATA_SCALE,0) = 0 AND nvl(DATA_PRECISION,0) = 0) THEN 'DECIMAL(38,18)'
@rakeshsingh
rakeshsingh / Java Code - Url Shortener.java
Last active September 6, 2024 11:01
Java Code - Url Shortener
package testjava;
import java.util.HashMap;
import java.util.Random;
/*
* URL Shortener
*/
public class URLShortener {
// storage for generated keys
@rakeshsingh
rakeshsingh / Oracle Script - Check Tablespace Size.sql
Last active August 19, 2020 13:42
Oracle Script - Check Tablespace Size
SELECT /* + RULE */
df.tablespace_name AS "Tablespace"
,df.bytes / (1024 * 1024 * 1024) AS "Size (GB)"
,Trunc(fs.bytes / (1024 * 1024 * 1024)) AS "Free (GB)"
FROM (
SELECT tablespace_name
,Sum(bytes) AS bytes
FROM dba_free_space
GROUP BY tablespace_name
) fs
SELECT OBJECT_TYPE
,OBJECT_SCHEMA
,OBJECT_NAME
FROM (
SELECT 'TABLE' AS OBJECT_TYPE
,TABLE_NAME AS OBJECT_NAME
,TABLE_SCHEMA AS OBJECT_SCHEMA
FROM information_schema.TABLES
UNION
@rakeshsingh
rakeshsingh / python-redshift-pg8000-connection.py
Last active August 19, 2020 13:43
Python Redshift Connection using PG8000
import json
import pg8000 as dbapi
from pprint import pprint
def getconnection(database,host,port,user,password):
conn= None
try:
conn=dbapi.connect(database=database,host=host, port=port,\
user=user,password=password,ssl=True)
except Exception as err: