From: Vicky Soni - Quipment India <vicky.soni@quipment.nl>
To: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13601: bit as quoted column in output
Date: Wed, 23 Sep 2015 06:35:13 +0000
Message-ID: <81f168923ffa4f08b4cdcaae58cd2ba4@Strand.quipment.local> (raw)
In-Reply-To: <CAEepm=3FmTVJt+VMU5o4--fr_smBXFwTZBedfZShZEQJws2TdA@mail.gmail.com>
References: <20150901124233.2090.28039@wrigleys.postgresql.org>
<CAKFQuwaKMOLaF1QL80qf1knGZw5KnozExCUSvKz8iX5nXJ_Mww@mail.gmail.com>
<640a4cb4678b4d0f8afc6e8d65af5405@Strand.quipment.local>
<CAEepm=3FmTVJt+VMU5o4--fr_smBXFwTZBedfZShZEQJws2TdA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Hi Thomas,
In this case, we are not able to retrieve correct datatype of returning function when calling from Application. In our case it is DOTNET and we use NPGSQL.
Is this a bug? Can we expect fix for this or should we live with same?
Please advice.
Thanks & Regards,
Vicky Soni
Database Administrator
-----Original Message-----
From: Thomas Munro [mailto:thomas.munro@enterprisedb.com]
Sent: 23 September 2015 08:28
To: Vicky Soni - Quipment India <vicky.soni@quipment.nl>
Cc: David G. Johnston <david.g.johnston@gmail.com>; pgsql-bugs@postgresql.org
Subject: Re: [BUGS] BUG #13601: bit as quoted column in output
On Thu, Sep 3, 2015 at 12:21 AM, Vicky Soni - Quipment India <vicky.soni@quipment.nl> wrote:
> Please refer following code and attached screenshots.
>
> create or replace function bit_return_testing() returns table (OutBit
> bit) as $BODY$ declare SQL VARCHAR; Begin sql:='select cast(1 as bit)
> '; raise notice '%',SQL; RETURN QUERY EXECUTE SQL; end; $BODY$
> LANGUAGE plpgsql VOLATILE
> COST 100
> ROWS 1000;
>
> select * from bit_return_testing();
>
> It give me output like this.
>
> [picture of PGAdmin showing a column's type as: "bit"]
In this case, Postgres is losing track of the typmod and giving your client PQftype(...) = 1560 (the OID for bit) and PQfmod(...) = -1.
PGAdmin is then calling format_type(1560, -1) to find out how to display that, which gives '"bit"' (bit with double quotes).
That's because format_type is designed to write out type names that can survive round trips for use by pg_dump, and, somewhat suprisingly, "bit" with double quotes means bit with typmod -1 whereas bit without double quotes means bit with typmod 1 AKA bit(1). Gory details here:
http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/adt/format_type.c> Now if I call same statement directly, i.e.
>
> select cast(1 as bit) ;
>
> It gives me output like this.
>
> [Picture of PGAdmin showing a column's type as: bit(1)]
In this case PQftype(...) = 1560 and PQfmod(...) = 1, which format_type renders as 'bit(1)' (without double quotes).
> Now my question/doubt/concern was why did it throw “bit” to me into first example and not simple bit?
Functions don't track the typmods of arguments or return values (including the out arguments that are used to implement RETURNS TABLE). You can write them, but they're discarded, so your data type bit AKA bit(1) was replaced with bit with typmod -1 AKA "bit".
--
Thomas Munro
http://www.enterprisedb.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: vicky.soni@quipment.nl, thomas.munro@enterprisedb.com, david.g.johnston@gmail.com
Subject: Re: BUG #13601: bit as quoted column in output
In-Reply-To: <81f168923ffa4f08b4cdcaae58cd2ba4@Strand.quipment.local>
References: <20150901124233.2090.28039@wrigleys.postgresql.org> <CAKFQuwaKMOLaF1QL80qf1knGZw5KnozExCUSvKz8iX5nXJ_Mww@mail.gmail.com> <640a4cb4678b4d0f8afc6e8d65af5405@Strand.quipment.local> <CAEepm=3FmTVJt+VMU5o4--fr_smBXFwTZBedfZShZEQJws2TdA@mail.gmail.com> <81f168923ffa4f08b4cdcaae58cd2ba4@Strand.quipment.local>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox