On Mon, May 21, 2018 at 12:54:56PM -0400, Tom Lane wrote:
> Alexey Dokuchaev writes:
> > Quick reality check question: are count(*) vs. count(_) equivalent
> > above?
>
> Only if _ is guaranteed non-null ... which, as a rowtype result, it
> probably is. But I'd use count(*) if you're concerned a
Alexey Dokuchaev writes:
> Quick reality check
> question: are count(*) vs. count(_) equivalent above?
Only if _ is guaranteed non-null ... which, as a rowtype result, it
probably is. But I'd use count(*) if you're concerned about speed.
regards, tom lane
On Mon, May 21, 2018 at 12:20:52PM -0400, Tom Lane wrote:
> Alexey Dokuchaev writes:
> > On Mon, May 21, 2018 at 10:45:27AM -0400, Tom Lane wrote:
> >> OP could do something like
> >>select json_agg(_) as j, count(*) as c INTO r FROM (
>
> > Thanks, I've arrived at the same solution (using lo
Alexey Dokuchaev writes:
> On Mon, May 21, 2018 at 10:45:27AM -0400, Tom Lane wrote:
>> OP could do something like
>> select json_agg(_) as j, count(*) as c INTO r FROM (
> Thanks, I've arrived at the same solution (using local RECORD) eventually.
> It works as intended, but I still need to
On Mon, May 21, 2018 at 10:45:27AM -0400, Tom Lane wrote:
> OP could do something like
>
> declare r record;
> ...
> select json_agg(_) as j, count(*) as c INTO r FROM (
> SELECT foo, bar, baz ...
> FROM t1, t2, t3 WHERE ...) AS _;
>
> This would be slightly more expensive
"David G. Johnston" writes:
>> Is it possible to obtain the
>> first ROW_COUNT (after SELECT) without performing it twice?
> Not directly, no. You should execute the inner query to a temporary table
> than perform your counting and json_agg from that.
OP could do something like
declar
On 05/21/2018 05:54 AM, Alexey Dokuchaev wrote:
Hi,
I'm seeing somewhat confusing results here with 9.6.8, and cannot find
the answer in the docs or google.
I'm returning JSON array (or any array, it does not make a difference)
from my plpgsql function like this:
OUT retcode int,
OUT
On Mon, May 21, 2018 at 5:54 AM, Alexey Dokuchaev wrote:
> result := json_agg(_) FROM (
> SELECT foo, bar, baz ...
> FROM t1, t2, t3 WHERE ...) AS _; -- this works fine
>
> GET DIAGNOSTICS retcode = ROW_COUNT;-- always returns 1
>
> I'd expected `retcode' to c