From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Bruce Momjian <bruce(at)momjian(dot)us> |
Cc: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: proposal: doc: simplify examples of dynamic SQL |
Date: | 2015-03-20 15:54:24 |
Message-ID: | CAKFQuwZcF2VncGovvE525g8qjs0aqVykbXiOMt7_jFLJ=quHyA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Looking at
http://momjian.us/tmp/pgsql/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
The paired example at the top of the patch has two things worth considering.
1. The layout of the format version is different, with respect to newlines,
than the quote version; but while using newlines for the mandatory
concatenation is good having an excessively long format string isn't
desirable and so maybe we should show something like:
EXECUTE format('SELECT count(*) FROM %I '
|| 'WHERE inserted_by = $1 AND insert <= $2', tabname)
INTO c
USING checked_user, checked_date
2. There is a recent posting pointing out the fact that the first query did
not use quote_ident(tabname) but instead did tabname::regclass, which calls
quote_ident internally. While there is a choice is that situation with
format you must pass in an unquoted label and so must not use
tabname::regclass. I think the first example should be written to use
quote_ident(tabname).
As regards the ::regclass behavior I would need see it current treatment
and recommended usage in the docs in order to form an opinion on how it
interacts with quote_literal and %I.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2015-03-20 16:04:04 | Re: [PATCH] two-arg current_setting() with fallback |
Previous Message | David G. Johnston | 2015-03-20 15:43:21 | Re: proposal: doc: simplify examples of dynamic SQL |