From: | rob stone <floriparob(at)tpg(dot)com(dot)au> |
---|---|
To: | "[Quipsy] Markus Karg" <karg(at)quipsy(dot)de>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Cast INTEGER to BIT confusion |
Date: | 2023-08-17 12:57:15 |
Message-ID: | 4489a1c28b0d5733ff29332b168b1b62fa75994c.camel@tpg.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
On Tue, 2023-08-15 at 08:49 +0000, [Quipsy] Markus Karg wrote:
>
>
>
> Hello PostgreSQL Community,
>
> I have 25+ years of experience with some other RDBMS, but I am a
> PostgreSQL starter, so I assume the following is rather a simple
> beginner’s question…:
>
> I like to store just a single bit but that can be either 1 or 0, so I
> tried to do this:
>
> CREATE TABLE T (c BIT);
> INSERT INTO T VALUES (1);
> -- I MUST NOT change both lines in any way as these are part of a
> third-party application!
>
> Unfortunately this tells me:
>
> column "c" is of type bit but expression is of type integer
>
> So I logged in as a cluster admin and I tried this:
>
> CREATE CAST (integer AS bit) WITH INOUT AS IMPLICIT;
>
> Unfortunately that tells me:
>
> cast from type integer to type bit already exists
>
> This is confusing! Apparently PostgreSQL 15.3 comes with the needed
> cast out-of-the-box but it does not apply it? This is confusing!
>
> What is my fault?
>
> Thanks!
> -Markus
It works thus:-
postgres 15.4 =# CREATE TABLE T (c BIT);
CREATE TABLE
postgres 15.4 =# insert into T values (B'1');
INSERT 0 1
postgres 15.4 =# select * from t;
c
---
1
(1 row)
See section 9.6 in the doco.
HTH,
Rob
From | Date | Subject | |
---|---|---|---|
Next Message | Erik Wienhold | 2023-08-17 13:14:16 | Re: Cast INTEGER to BIT confusion |
Previous Message | Andreas Joseph Krogh | 2023-08-17 10:10:11 | Sv: Base files compatibility between PG11 and PG15 |