Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YqNjd-0004fu-7X for pgsql-sql@arkaria.postgresql.org; Thu, 07 May 2015 15:29:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YqNjc-0006dI-OK for pgsql-sql@arkaria.postgresql.org; Thu, 07 May 2015 15:29:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YqNjb-0006d8-HI for pgsql-sql@postgresql.org; Thu, 07 May 2015 15:29:11 +0000 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YqNjY-0006Yt-I8 for pgsql-sql@postgresql.org; Thu, 07 May 2015 15:29:10 +0000 Received: by wgin8 with SMTP id n8so47304799wgi.0 for ; Thu, 07 May 2015 08:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=Xh+FSmBALDWcNzWY7b7Bk7qbMVeFX4qellMlxytBd6k=; b=E4s6kIopb8HLPSCwMk34X7ZiQmZkSDl7PLhN62cbexci5A8ZU+pWa9mojqRkOy5LAD nSPQ5DA7WQSK4a9wUjhd7vjvC+Fo+7YEX+pRG3j3Y3NViNqpAmJIs69DcfEJVnt/EIoJ tE5ESC0X0TDMMYxIZxuvLnWJtKAMNAr0HMuEiA2bALQG/uruZokHR1UAzYl5BMKX0sTI I2FVcqseWJbuQpB4KXpw0sGgaus5sono517FMn9b1pY9jiomGe7n0PlUwHVuEyUMEIbL NR1MosiWuW/SaOosWEGVPnvc7Ur0Z0BAGoas4B42PgsE2cCd6Bd5yuzS98FTYiqu5WFf Z4bA== X-Received: by 10.180.91.40 with SMTP id cb8mr7685434wib.64.1431012546863; Thu, 07 May 2015 08:29:06 -0700 (PDT) Received: from timbomac.home (host86-147-75-147.range86-147.btcentralplus.com. [86.147.75.147]) by mx.google.com with ESMTPSA id a4sm3179246wic.1.2015.05.07.08.29.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 May 2015 08:29:05 -0700 (PDT) Message-ID: <554B84C0.1070007@gmail.com> Date: Thu, 07 May 2015 16:29:04 +0100 From: Tim Dudgeon User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: generating json without nulls References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------020109050602040309020000" X-Pg-Spam-Score: -1.3 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org This is a multi-part message in MIME format. --------------020109050602040309020000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit That's not going to work. I want the row, I just don't want the values that are null. Tim On 07/05/2015 16:16, Andreas Joseph Krogh wrote: > På torsdag 07. mai 2015 kl. 12:56:42, skrev Tim Dudgeon > >: > > Hi All! > I'm using the postgres json functions to generate json for values in a > table. > Something like this: > > SELECT row_to_json(a_table) FROM a_table > > But my data has lots of null values and that results in json > attributes > like this: > > "colname":null > > I want to exclude those values from the json and only include non-null > values. > Any idea how to best go about this? > > Tim > > WHERE colname IS NOT NULL ? > -- > *Andreas Joseph Krogh* > CTO / Partner - Visena AS > Mobile: +47 909 56 963 > andreas@visena.com > www.visena.com > --------------020109050602040309020000 Content-Type: multipart/related; boundary="------------040903060305030204080808" --------------040903060305030204080808 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit That's not going to work. I want the row, I just don't want the values that are null.

Tim

On 07/05/2015 16:16, Andreas Joseph Krogh wrote:
 På torsdag 07. mai 2015 kl. 12:56:42, skrev Tim Dudgeon <tdudgeon.ml@gmail.com>:
Hi All!
I'm using the postgres json functions to generate json for values in a
table.
Something like this:

SELECT row_to_json(a_table) FROM a_table

But my data has lots of null values and that results in json attributes
like this:

"colname":null

I want to exclude those values from the json and only include non-null
values.
Any idea how to best go about this?

Tim
 
WHERE colname IS NOT NULL ?
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 

--------------040903060305030204080808 Content-Type: image/png Content-Transfer-Encoding: base64 Content-ID: iVBORw0KGgoAAAANSUhEUgAAAIUAAAAYCAYAAADUIj6hAAAABHNCSVQICAgIfAhkiAAABzBJ REFUaEPtmNFxHDcMhmVP3i1VECpvnjzkVIHWFfhcgVcVRKrAUgWRK/C6Al8H3lTgy0PGbzFd Qc4VJP/HADs43q6kROeJNbOYgQACIAgCWJKng4MZ5gxUGXh0U0b+SIuF9G+EWXj2Q15vbrE/ NPtk9uub7Gfdt5mBx1NhqSEo8HshjbEUtlO2yIM9tsx5dZP9rPt2MzDZFAqZE4LGcFjdsg3s aQaHt7fY70X949OnaS+OZidDBkavD33157L4xaw2os+Mp/DAC10l2XhOCeStj0W5ajrJL8Wf Ci80Xgf9vVlrhg9yRONe/f7xI2vNsIcM7JwU9o6oGyJrLT8JOA1aX9sKP4wl94bAniukEbo/ n7YPmuTETzIab4Y9ZWCrKexd8M58lxPCvvD6aihfvexbEQoPYO8NQRO0JnddGO6FJYaVsBde 7cXj7KRk4LsqDxQzCYeGsJNgaXZe+JXkyGgWINq3Gp+bHNILz+wEYs5qH1eJrouNrpDXtk4O 6x1IvtD40GWyJYYdkF0jIbYZlN16xygIgl9smbMDsmFdfAKb23xGB8H/mv3tOJfArs1kukk7 9DEPdQ5u0g1vCvvqKXIW8mZYW+F3Tg4r8HvZkQCCLydK8EFMQCe5N8Rg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