Thread: ...
hi, i'm trying to drop table in plpgsql trigger. the problem is that table name depends on ID of object that is to be removed. so: <cut> declare t text; begin t := 'objects' || trim(OLD.id); drop table t; end </cut> psql prints error: <cut> ERROR: parser: parse error at or near "$1" </cut> what may be the problem? what does it mean "$1"? i don't have any function arguments. any ideas? thanx. /--------------------------------------------------------/ /- Piotr Stelmaszyk |---- Student of Computer Science ---/ /------------------ | at Poznan University of Technology / /----- mailto:kelman@fanthom.math.put.poznan.pl ---------/ /----- mailto:kelman@alpha.net.pl -----------------------/ /--------------------------------------------------------/
At 18:49 +0300 on 07/06/1999, Piotr Stelmaszyk wrote: > what may be the problem? what does it mean "$1"? i don't have > any function arguments. > > any ideas? thanx. The problem is that the parameter passed to "drop table" should not be a string but a table. You don't write DROP TABLE 'my_table', but DROP TABLE my_table. So you are passing it the wrong kind of object. You should pass a table, not the name of a table. There is a difference. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma
Monday, June 07, 1999, 6:23:56 PM, you wrote: HM> DROP TABLE 'my_table', HM> but HM> DROP TABLE my_table. thank You i _do_ understand problem now, but i still don't know the sollution. How can I drop table which name is evaluated from variable and text? (in plpgsql of course) /--------------------------------------------------------/ /- Piotr Stelmaszyk |---- Student of Computer Science ---/ /------------------ | at Poznan University of Technology / /----- mailto:kelman@fanthom.math.put.poznan.pl ---------/ /----- mailto:kelman@alpha.net.pl -----------------------/ /--------------------------------------------------------/
Monday, June 07, 1999, 6:23:56 PM, you wrote: HM> DROP TABLE 'my_table', HM> but HM> DROP TABLE my_table. thank You i _do_ understand problem now, but i still don't know the sollution. How can I drop table which name is evaluated from variable and text? (in plpgsql of course) /--------------------------------------------------------/ /- Piotr Stelmaszyk |---- Student of Computer Science ---/ /------------------ | at Poznan University of Technology / /----- mailto:kelman@fanthom.math.put.poznan.pl ---------/ /----- mailto:kelman@alpha.net.pl -----------------------/ /--------------------------------------------------------/
Monday, June 07, 1999, 6:23:56 PM, you wrote: HM> DROP TABLE 'my_table', HM> but HM> DROP TABLE my_table. thank You i _do_ understand problem now, but i still don't know the sollution. How can I drop table which name is evaluated from variable and text? (in plpgsql of course) /--------------------------------------------------------/ /- Piotr Stelmaszyk |---- Student of Computer Science ---/ /------------------ | at Poznan University of Technology / /----- mailto:kelman@fanthom.math.put.poznan.pl ---------/ /----- mailto:kelman@alpha.net.pl -----------------------/ /--------------------------------------------------------/
Monday, June 07, 1999, 6:23:56 PM, you wrote: HM> DROP TABLE 'my_table', HM> but HM> DROP TABLE my_table. thank You i _do_ understand problem now, but i still don't know the sollution. How can I drop table which name is evaluated from variable and text? (in plpgsql of course) ps. sorry for previous "subjectless" email /--------------------------------------------------------/ /- Piotr Stelmaszyk |---- Student of Computer Science ---/ /------------------ | at Poznan University of Technology / /----- mailto:kelman@fanthom.math.put.poznan.pl ---------/ /----- mailto:kelman@alpha.net.pl -----------------------/ /--------------------------------------------------------/
>>>>> "PS" == Piotr Stelmaszyk <kelman@fanthom.math.put.poznan.pl> writes: PS> Monday, June 07, 1999, 6:23:56 PM, you wrote:HM> DROP TABLE 'my_table',HM> butHM> DROP TABLE my_table.PS> thank YouPS>i _do_ understand problem now, but i still don't know the sollution.PS> How can I drop table which name is evaluatedfrom variable and text?PS> (in plpgsql of course) I think there is no solution this problem in 'plpgsql' -- Anatoly K. Lasareff Email: tolik@icomm.ru Senior programmer
At 09:31 +0300 on 08/06/1999, Anatoly K. Lasareff wrote: > PS> Monday, June 07, 1999, 6:23:56 PM, you wrote: > HM> DROP TABLE 'my_table', > HM> but > HM> DROP TABLE my_table. > PS> thank You > PS> i _do_ understand problem now, but i still don't know the sollution. > PS> How can I drop table which name is evaluated from variable and text? > PS> (in plpgsql of course) > > I think there is no solution this problem in 'plpgsql' Neither do I. I think you will have to write in C or in pl/pgtcl. Either that, or have a big conditional that maps all possible combinations. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma