Re: proposal: doc: simplify examples of dynamic SQL - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: proposal: doc: simplify examples of dynamic SQL
Date
Msg-id CAKFQuwZcF2VncGovvE525g8qjs0aqVykbXiOMt7_jFLJ=quHyA@mail.gmail.com
Whole thread
In response to Re: proposal: doc: simplify examples of dynamic SQL  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: proposal: doc: simplify examples of dynamic SQL
List pgsql-hackers

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.


pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: proposal: doc: simplify examples of dynamic SQL
Next
From: Robert Haas
Date:
Subject: Re: [PATCH] two-arg current_setting() with fallback