By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,512 Members | 747 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,512 IT Pros & Developers. It's quick & easy.

Creating a SQL variable to hold a table name

P: n/a
Yow, there's got to be an easier way to do this ...

I'm trying to create a script file that will process a table whose name
is constructed from an integer argument passed into the script file. E.g.,

$ psql -f my_script.sql -v id=24
DELETE FROM table_00024 WHERE ...

Here's what I came up with so far:
\set QUIET 1
\pset footer 0
\o /tmp/reset_this_id.sql
\qecho '\\set this_table `printf \'table_%.5d\'' :id '`'
\i /tmp/reset_this_id.sql

\qecho :id
\qecho :this_table

So, it works, but I'm wondering if I missed an easy alternative.

Jeff Boes vox 269.226.9550 ext 24
Database Engineer fax 269.349.9076
Nexcerpt, Inc.
...Nexcerpt... Extend your Expertise
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.