Re: proposal: doc: simplify examples of dynamic SQL
От | David G. Johnston |
---|---|
Тема | Re: proposal: doc: simplify examples of dynamic SQL |
Дата | |
Msg-id | CAKFQuwZcF2VncGovvE525g8qjs0aqVykbXiOMt7_jFLJ=quHyA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: proposal: doc: simplify examples of dynamic SQL ("David G. Johnston" <david.g.johnston@gmail.com>) |
Ответы |
Re: proposal: doc: simplify examples of dynamic SQL
(Bruce Momjian <bruce@momjian.us>)
|
Список | pgsql-hackers |
<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Looking at <a href="http://momjian.us/tmp/pgsql/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN">http://momjian.us/tmp/pgsql/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN</a></div><div class="gmail_default"style="font-family:arial,helvetica,sans-serif"><br /></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thepaired example at the top of the patch has two things worth considering.</div><divclass="gmail_default" style="font-family:arial,helvetica,sans-serif"><br /></div><div class="gmail_default"style="font-family:arial,helvetica,sans-serif">1. The layout of the format version is different, withrespect to newlines, than the quote version; but while using newlines for the mandatory concatenation is good havingan excessively long format string isn't desirable and so maybe we should show something like:</div><div class="gmail_default"style="font-family:arial,helvetica,sans-serif"><br /></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">EXECUTEformat('SELECT count(*) FROM %I '</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">||'WHERE inserted_by = $1 AND insert <= $2', tabname)</div><div class="gmail_default"style="font-family:arial,helvetica,sans-serif">INTO c</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">USINGchecked_user, checked_date</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br/></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">2.There is a recent posting pointing out the fact that the first query didnot use quote_ident(tabname) but instead did tabname::regclass, which calls quote_ident internally. While there is achoice is that situation with format you must pass in an unquoted label and so must not use tabname::regclass. I thinkthe first example should be written to use quote_ident(tabname).</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br/></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Asregards the ::regclass behavior I would need see it current treatment andrecommended usage in the docs in order to form an opinion on how it interacts with quote_literal and %I.</div><div class="gmail_default"style="font-family:arial,helvetica,sans-serif"><br /></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">DavidJ.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br/></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br/></div></div>
В списке pgsql-hackers по дате отправления:
Предыдущее
От: "David G. Johnston"Дата:
Сообщение: Re: proposal: doc: simplify examples of dynamic SQL