Re: Dynamic SQL
От | Richard Huxton |
---|---|
Тема | Re: Dynamic SQL |
Дата | |
Msg-id | 40BD8E7E.9080200@archonet.com обсуждение исходный текст |
Ответ на | Dynamic SQL (Hadley Willan <hadley.willan@deeperdesign.co.nz>) |
Список | pgsql-general |
Hadley Willan wrote: > Hi all, > I'd like to write a function that would allow me to verify some > attributes on a table so that I could give a meaningful error message... > > constructedSql = ''SELECT INTO recCheckObject * FROM '' || > tableName || '' WHERE '' || idColumn || '' = '' || objectId; > EXECUTE constructedSql; > However, when you try and run this it's like the SELECT INTO <record> is > failing to pickup the reference to the declared variable? Sounds likely, and (without testing anything) I wouldn't expect it to work. Indeed, checking the manuals: plpgsql / basic statements (37.6.4) "The results from SELECT commands are discarded by EXECUTE, and SELECT INTO is not currently supported within EXECUTE. There are two ways to extract a result from a dynamically-created SELECT: one is to use the FOR-IN-EXECUTE loop form described in Section 37.7.4, and the other is to use a cursor with OPEN-FOR-EXECUTE, as described in Section 37.8.2." There's your solution - you need to use the FOR rec IN ... looping construct. -- Richard Huxton Archonet Ltd
В списке pgsql-general по дате отправления: