Sql

Sql - Reference

postgres cli

\l list databases
\c DATABASE NAME connect/switch to database
\dt list tables
\d TABLE NAME describe table
\o FILE NAME \o save query result to a file
\! shell command run external shell command

You can do \l to list all the databases, use \c to connect to one database, use \d to list tables in this database

Sql - How To

drop column

ALTER TABLE oneview_frozencharge DROP COLUMN product_fee_charge_is_user_input_required;

rename tableALTER TABLE oneview_incomeprofile RENAME COLUMN business_unit_id TO adviser_business_unit_id; ALTER TABLE oneview_incomeprofile RENAME COLUMN adviser_business_unit_id TO business_unit_id;

save query result to a file```

start

data.txt

…run the psql commands…e.g. 

ended

docker-compose –file docker-compose-dev.yml exec postgres cat data.txt


# loading curo_sheet in psql
### load curo_sheet into postgres

```sql
DROP TABLE curo_sheet;
CREATE TABLE curo_sheet
(
"Entity Display Name" varchar,
"Entity Logical Name" varchar,
"Attribute DisplayName" varchar,
"Attribute Logical name" varchar,
"Attribute Type" varchar,
"On Form?" varchar,
"Form Section" varchar,
"Mandatory  Recommended" varchar,
"Picklist option set" varchar,
"Lookup target entity" varchar,
"String max length" varchar,
"Numeric min value" varchar,
"Numeric max value" varchar,
"Numeric precision" varchar,
"DateTime just Date" varchar,
"Boolean false value" varchar,
"Boolean default value" varchar,
"Audited" varchar,
"Searchable" varchar,
"Description" varchar,
"Type" varchar
);

\copy curo_sheet FROM '/Users/yuhao.huang/Documents/curo_sheet.csv' DELIMITER ',' CSV HEADER; 

Usage

psql

select "Entity Display Name", "Picklist option set" from curo_sheet where "Picklist option set" like '%Annual%';