Skip to content

Instantly share code, notes, and snippets.

View amitchhajer's full-sized avatar

Amit Chhajer amitchhajer

View GitHub Profile
@amitchhajer
amitchhajer / add_row.sh
Created March 31, 2017 06:18 — forked from kristjan/add_row.sh
Google Spreadsheet row insertion example
# $auth from auth.sh
# $spreadsheet_id from get_spreadsheets.sh
# $worksheet_id from get_worksheets.sh
curl \
--header "Authorization: GoogleLogin auth=$auth" \
--header 'Content-Type: application/atom+xml' \
-d @data.xml \
-X POST \
"https://spreadsheets.google.com/feeds/list/$spreadsheet_id/$worksheet_id/private/full"
# Example data in data.xml
SELECT
current_database(), schemaname, tablename, /*reltuples::bigint, relpages::bigint, otta,*/
round(avg((CASE WHEN otta=0 THEN 0.0 ELSE sml.relpages::float/otta END)::numeric),1) AS tbloat,
round(avg(CASE WHEN relpages < otta THEN 0 ELSE bs*(sml.relpages-otta)::BIGINT END), 0) AS wastedbytes
FROM (
SELECT
schemaname, tablename, cc.reltuples, cc.relpages, bs,
CEIL((cc.reltuples*((datahdr+ma-
(CASE WHEN datahdr%ma=0 THEN ma ELSE datahdr%ma END))+nullhdr2+4))/(bs-20::float)) AS otta,
SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS index
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS table
FROM (
SELECT *, total_bytes-index_bytes-coalesce(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS table_name
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes