executing query results withing psql - Mailing list pgsql-general

From Reece Hart
Subject executing query results withing psql
Date
Msg-id 1204727393.6406.68.camel@snafu
Whole thread Raw
List 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


pgsql-general by date:

Previous
From: "pobox@verysmall.org"
Date:
Subject: PostgreSQL vs. MySQL benchmarks on SMP FreeBSD 7.0
Next
From: David Fetter
Date:
Subject: Re: [DOCS] Documenting a DB schema