Postgresql Basic Usage Notes

Posted by zhulinpinyu on March 31, 2016

Postgresql Basic Usage Notes

/img/in-post/2016-03-31-postgresql-logo.png

Basic usage

Login

psql -h 0.0.0.0 -U username -p 5432

show DB

\l

switch DB

\c db_name

show tables in DB

\dt

use \? see more detail

show view in DB

\dv

Show view detail with create shell

 \d+ view_name

SQL usage

split one field value to multi field

split_part 示例:
split_part(lgl_category, '-',1)
split_part(lgl_category, '-‘,3)

示例:
SELECT *,upper(split_part(lgl_category, '-',1)) as vtype, upper(split_part(lgl_category, '-',3)) as vsubtype FROM lg.venuesview_3857

lgl_category is field name

Uppercase method

upper:字段值转换为大写

concat multi field to one field

select lgl_category,concat(lgl_description,'(',lgl_description_eng,')') from lg.category_raw

lgl_description and lgl_description_eng are field name