:1,.−1dTo delete all rows above the current lin, press d (delete) followed by capital G (end of document):
d + G
Minimalistic Oracle contains a collection of practical examples from my encounters with Oracle technologies. When relevant, I also write about other technologies, like Linux or PostgreSQL. Many of the posts starts with "how to" since they derive directly from my own personal experience. My goal is to provide simple examples, so that they can be easily adapted to other situations.
:1,.−1dTo delete all rows above the current lin, press d (delete) followed by capital G (end of document):
d + G
SELECT bug_number, creation_date FROM ad_bugs WHERE bug_number IN ( -- AD/TXK Delta 13 driver patch numbers '35163625','35163283','35163924','35162879' ) ORDER BY creation_date DESC;If no rows are returned, you are not on AD/TXK Delta 13, yet
export PGPASSWORD=mysecretpassword
psql -h myserver.oric.no -d db01 -U scott -v schema=scott -v table=mytable -f myquery.sql
The query in myquery.sql can then referance the "schema" and "table" variables, like this:
SELECT att.attname AS column_name FROM pg_attribute att JOIN pg_class cls ON cls.oid = att.attrelid JOIN pg_namespace ns ON ns.oid = cls.relnamespace WHERE ns.nspname = :'schema' AND cls.relname = :'table' AND att.attnotnull AND att.attnum > 0 AND NOT att.attisdropped;
SELECT conname, condeferrable, condeferred FROM pg_constraint WHERE conrelid in ( 'mytable1'::regclass,'mytable2'::regclass) AND contype='f'; conname | condeferrable | condeferred ------------------------------+---------------+------------- mytable1_id_fkey | f | f mytable1_id_fkey | f | f mytable2_id_fkey | f | f
-- Terminate all connections from user "sales" SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE usename = 'sales';In my case the result was:
pg_terminate_backend ---------------------- t t (2 rows)
SELECT USERNAME, COUNT(*) FROM v$session WHERE type <> 'BACKGROUND' GROUP BY username;Would be
SELECT datname, usename AS username, COUNT(*) FROM pg_stat_activity WHERE backend_type = 'client backend' GROUP BY datname, usename ORDER BY datname, usename;Example output:
datname | username | count ----------+-------------------+------- postgres | postgres | 1 postgres | postgres_exporter | 1 mydb | myser | 2 (3 rows)
vi myfilePress the escape key to enter interactive mode, then type
:%s/.*/\L&/Press escape, then save + exit the editor:
:wq