470,614 Members | 1,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Creating a SQL variable to hold a table name

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. http://www.nexcerpt.com
...Nexcerpt... Extend your Expertise
Jul 19 '05 #1
0 3416

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Billy Cormic | last post: by
7 posts views Thread by nog | last post: by
6 posts views Thread by deejayquai | last post: by
6 posts views Thread by Vmusic | last post: by
3 posts views Thread by mghale | last post: by
6 posts views Thread by Chris Carlen | last post: by
3 posts views Thread by Kelicula | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.