On 2/8/17 2:51 PM, Alvaro Herrera wrote:
I always have a bit of mixed feelings with these kind of string
manipulations on dynamic SQL.
It may look a bit nasty, but locking tables for long periods (or being
without an important index for a period) is much worse in production

I think posting a recipe in the wiki is a great idea (especially if it handles corner cases like constraints). I'm not so keen on trying to code it entirely in psql though. I think it'd be a lot cleaner to have a plpgsql function that uses format() to construct the appropriate commands to run and then spit that out as text. Users can either cut and paste that, or they can \gset it to a variable that they then execute, or they can capture the output to a file which they execute.

The big advantage to this is by default you see what commands would be run, but you can still fully automate if you want to without much extra effort.
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)

Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to