File: postgres_update_seqs.sh

package info (click to toggle)
phpbb3 3.0.10-4%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 58,336 kB
  • sloc: php: 447,853; sql: 2,079; sh: 529; makefile: 47; perl: 45
file content (11 lines) | stat: -rwxr-xr-x 440 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
[ -z "$1" -o ! -f "$1" ] && echo "No schema given or schema does not exist." && exit 1
schema="$1"
for s in $(sed -n 's/^CREATE SEQUENCE \(.\+\);/\1/ p' < $schema); do
	for c in $(grep $s $schema | grep nextval | awk '{print $1}'); do
#		echo "SELECT MAX($c) FROM ${s#_seq};"
#		echo "SELECT nextval('$s');"
		echo "ALTER SEQUENCE $s MINVALUE 1;"
		echo "SELECT setval('$s', (SELECT MAX($c) FROM ${s%_seq})+1, false);"
	done
done