executing query results withing psql

From: Reece Hart <reece(at)harts(dot)net>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: executing query results withing psql
Date: 2008-03-05 14:29:53
Message-ID: 1204727393.6406.68.camel@snafu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is there a way to generate and directly execute query results within
psql? Essentially, I want eval within psql.

For example, a lot of us generate DDL commands using queries, like this:
=> SELECT 'GRANT SELECT ON VIEW "'||table_schema||'.'||
table_name||'" TO budget_view;'
FROM information_schema.views
WHERE table_schema='budget';

To execute such results, I do one these:
* in a shell, pipe between psqls (ie, psql -Atc 'select ...' | psql)
* within psql, execute and copy-paste
* within psql, use \g file, then \i file
* within psql, use \g |psql

I like the \g + \i option most for consistency and robustness (don't
have to specify the db connection or worry about connecting to the wrong
db), but what I really want is a hypothetical \eval to execute the query
and then execute the results.

Any such thing?

Thanks,
Reece

--
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2008-03-05 15:05:27 Re: [DOCS] Documenting a DB schema
Previous Message pobox@verysmall.org 2008-03-05 14:15:21 PostgreSQL vs. MySQL benchmarks on SMP FreeBSD 7.0