Skip to content

Instantly share code, notes, and snippets.

SELECT
-- Name of the Table
_V_TABLE.TABLENAME as "Table Name",
-- Column name
SUBSTR(_v_relation_column.attname || ' ', 1, 25) as "Column Name",
-- Statistics Details
CASE WHEN _v_statistic.recent IS NULL THEN 'not maintained '
ELSE
select * from (
select 'TRAINING' DB_NAME,'INT_SAMPLE_SALES' TABLE_NAME,'MONTH_ID' COLUMN_NAME,sum(sign(nvl(instr(MONTH_ID,'my_search_string'),0))) ROWS_COUNT from TRAINING..INT_SAMPLE_SALES
union all select 'TRAINING' DB_NAME,'INT_SAMPLE_SALES' TABLE_NAME,'SALE_QTY' COLUMN_NAME,sum(sign(nvl(instr(SALE_QTY,'my_search_string'),0))) ROWS_COUNT from TRAINING..INT_SAMPLE_SALES
union all select 'TRAINING' DB_NAME,'MERGE_DEMO1' TABLE_NAME,'FIRSTNAME' COLUMN_NAME,sum(sign(nvl(instr(FIRSTNAME,'my_search_string'),0))) ROWS_COUNT from TRAINING..MERGE_DEMO1
union all select 'TRAINING' DB_NAME,'MERGE_DEMO1' TABLE_NAME,'ID' COLUMN_NAME,sum(sign(nvl(instr(ID,'my_search_string'),0))) ROWS_COUNT from TRAINING..MERGE_DEMO1
union all select 'TRAINING' DB_NAME,'MERGE_DEMO1' TABLE_NAME,'LASTNAME' COLUMN_NAME,sum(sign(nvl(instr(LASTNAME,'my_search_string'),0))) ROWS_COUNT from TRAINING..MERGE_DEMO1
union all select 'TRAINING' DB_NAME,'MERGE_DEMO2' TABLE_NAME,'FIRSTNAME' COLUMN_NAME,sum(sign(nvl(instr(FIRSTNAME,'my_search_str
[nz@netezza ~]$ nzhealthcheck
Netezza System Health Check 2.3.1.2
Collecting monitoring data
Evaluating troubleshooting rules
************************************************************************
********************** System Health Check Report **********************
************************************************************************
Report generation date: 2016-10-21 14:48:06
***************************** MINI SYSINFO *****************************
+ Product : **********************
import csv
from openpyxl import Workbook
from openpyxl.cell import get_column_letter
f = open(r'/home/vithal/sample_text.txt')
csv.register_dialect('colons', delimiter=',')
reader = csv.reader(f, dialect='colons')
wb = Workbook()
dest_filename = r"/home/vithal/excel1.xlsx"
ws = wb.worksheets[0]
ws.title = "A Title"
vithal@vithal-Inspiron-3558:~$ pwd
/home/vithal
vithal@vithal-Inspiron-3558:~$ vi .pgpass
vithal@vithal-Inspiron-3558:~$ chmod 600 .pgpass
vithal@vithal-Inspiron-3558:~$ ls -la .pgpass
-rw------- 1 vithal vithal 97 Nov 30 19:13 .pgpass
vithal@vithal-Inspiron-3558:~$ more .pgpass
vithalxxxxx.xxxxxx.us-east-2.redshift.amazonaws.com:5439:training:trainee:trainee
vithal@vithal-Inspiron-3558:~$ sudo -i -u postgres
[sudo] password for vithal:
vithal@vithal-Inspiron-3558:~$ export PGDATABASE=training
vithal@vithal-Inspiron-3558:~$ export PGHOST=vithalxxxx.xxxxx.us-east-2.redshift.amazonaws.com
vithal@vithal-Inspiron-3558:~$ export PGPORT=5439
vithal@vithal-Inspiron-3558:~$ export PGUSER=trainee
vithal@vithal-Inspiron-3558:~$ export PGPASSWORD=trainee
vithal@vithal-Inspiron-3558:~$ psql
psql (9.3.20, server 8.0.2)
SSL connection (cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256)
Type "help" for help.
training=# copy sample_test_single_col from 's3://testbucket/Sample_fixed_width.txt' CREDENTIALS
training-# 'aws_access_key_id=xxxxxxx; aws_secret_access_key=yyyyyyyy' ;
INFO: Load into table 'sample_test_single_col' completed, 17 record(s) loaded successfully.
COPY
training=# select * from sample_test_single_col limit 2;
single_col
----------------------------------------------------
16524 01 10172012 3930621977 TXNPUES
191667 01 01142013 3714468136 GHAKASC QHJXDFM
(2 rows)
training=# copy sample_test_stage from 's3://testbucket/Sample_fixed_width.txt' CREDENTIALS
training-# 'aws_access_key_id=xxxxxxxx; aws_secret_access_key=yyyyyyyyy' fixedwidth 'col1:6,col2:4, col3:11,col4:12,col5:10,col6:8';
INFO: Load into table 'sample_test_stage' completed, 17 record(s) loaded successfully.
COPY
training=# select * from sample_test_stage limit 2;
col1 | col2 | col3 | col4 | col5 | col6
--------+------+-------------+--------------+------------+---------
191675 | 01 | 01142013 | 2368183100 | OUNHQEX | XUFQONY
191673 | 01 | 01142013 | 2632703881 | PAHFSAP | LUVIKXZ
CREATE OR REPLACE PROCEDURE return_result() RETURNS
REFTABLE(tab1) LANGUAGE NZPLSQL AS
BEGIN_PROC
BEGIN
-- Insert into REF TABLE
EXECUTE IMMEDIATE 'INSERT INTO ' || REFTABLENAME ||' values (111, 100,''ABC'',200)';
EXECUTE IMMEDIATE 'INSERT INTO ' || REFTABLENAME ||' values (112, 101,''AAA'',202)';
EXECUTE IMMEDIATE 'INSERT INTO ' || REFTABLENAME ||' values (113, 102,''BBB'',201)';
CREATE VIEW action_movies AS
SELECT *
FROM films
WHERE kind = 'Action';
training=# select * from action_movies;
code | title | kind | len
-------+------------+--------+----------
C_102 | Globe1 | Action | 01:40:00
C_101 | Globe | Action | 01:30:00