DROP IF ...
От | CG |
---|---|
Тема | DROP IF ... |
Дата | |
Msg-id | 20050524174454.67174.qmail@web32501.mail.mud.yahoo.com обсуждение исходный текст |
Ответы |
Re: DROP IF ...
|
Список | pgsql-sql |
PostgreSQL 7.4 ... I'm trying to find a way to drop a table via SQL if it contains 0 rows. Here was my thought: CREATE OR REPLACE FUNCTION dropif(text, bool) RETURNS bool AS 'DECLARE tblname ALIAS FOR $1; condition ALIAS FOR $2; BEGIN IF (condition) THEN EXECUTE(\'DROP TABLE "\' || tblname || \'";\'); END IF; RETURN \'t\'::bool; END;' LANGUAGE 'plpgsql' VOLATILE; ... then ... BEGIN; CREATE TABLE testtbl (i int4); SELECT dropif('testtbl',(SELECT count(*)::int4 FROM testtbl) = 0); ERROR: relation 286000108 is still open CONTEXT: PL/pgSQL function "dropif" line 6 at execute statement ... It makes sense. The select is still open when the table is going to be dropped. I need a different strategy. Please advise! CG __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
В списке pgsql-sql по дате отправления: