dbTalk Databases Forums  

Creating a SQL variable to hold a table name

comp.databases.postgresql.questions comp.databases.postgresql.questions


Discuss Creating a SQL variable to hold a table name in the comp.databases.postgresql.questions forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jeff Boes
 
Posts: n/a

Default Creating a SQL variable to hold a table name - 02-24-2004 , 02:50 PM






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 '`'
\o
\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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.