Skip to content

Instantly share code, notes, and snippets.

@matlads
Forked from mcnemesis/pg_col_resize.sh
Last active December 17, 2015 14:39
Show Gist options
  • Save matlads/5625931 to your computer and use it in GitHub Desktop.
Save matlads/5625931 to your computer and use it in GitHub Desktop.
Check for proper number of command line args.
#!/usr/bin/sh
if [ $# -ne 5 ]
then
echo "Usage: "$0" DBUSER DB TABLE COL NEWSIZE"
else
USER=$1
DB=$2
TABLE=$3
COL=$4
SIZE=$5
echo "Resizing COL ["$COL"] in TABLE ["$DB"."$TABLE"] to "$SIZE
psql $DB -U $USER <<SQL
SELECT atttypmod as "CURRENT_SIZE" FROM pg_attribute WHERE attrelid = '$TABLE'::regclass AND attname = '$COL';
UPDATE pg_attribute SET atttypmod = $SIZE+4 WHERE attrelid = '$TABLE'::regclass AND attname = '$COL';
SELECT atttypmod as "NEWSIZE" FROM pg_attribute WHERE attrelid = '$TABLE'::regclass AND attname = '$COL';
SQL
fi
@mcnemesis
Copy link

Sure. Makes us assume less...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment