pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: [Quipsy] Markus Karg <karg@quipsy.de>
Cc: Erik Wienhold <ewie@ewie.name>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: AW: AW: Cast INTEGER to BIT confusion
Date: Thu, 17 Aug 2023 09:18:14 -0400
Message-ID: <1819966.1692278294@sss.pgh.pa.us> (raw)
In-Reply-To: <015a3586e6dc40e0b1c3a4a1f3b1e44c@quipsy.de>
References: <fbc716336d544e93b6af5e11af3e4aa0@quipsy.de>
	<533487381.212078.1692100096551@office.mailbox.org>
	<84bd46dba5ec4097ba9663f46a1e5754@quipsy.de>
	<400164688.228966.1692109673749@office.mailbox.org>
	<015a3586e6dc40e0b1c3a4a1f3b1e44c@quipsy.de>

"[Quipsy] Markus Karg" <karg@quipsy.de> writes:
> I am giving up. While even `SELECT current_schemas(true)` correctly prints `xxx, pg_catalog` it still uses the original bit type. This is completely NOT as described in the documentation, where it is clearly told that pg_catalog only is searched immediately if NOT found in the search path.

That's probably because the grammar uses SystemTypeName (effectively
prepending "pg_catalog.") for any type that has special syntax called
out in the SQL standard.  You could get around that in various ways,
but they all involve changing the way the CREATE TABLE command is
written, because just plain "BIT" is a SQL-mandated special case.

> It seems it is simply impossible to run this application on PostgreSQL, and we have to stick with a different RDBMS. Very sad.

You could leave the type alone and instead fool with the properties of
the cast (see [1]).  As superuser:

regression=# create table t (f1 bit);
CREATE TABLE
regression=# insert into t values (1);
ERROR:  column "f1" is of type bit but expression is of type integer
LINE 1: insert into t values (1);
                              ^
HINT:  You will need to rewrite or cast the expression.
regression=# select * from pg_cast where castsource = 'integer'::regtype and casttarget = 'bit'::regtype;
  oid  | castsource | casttarget | castfunc | castcontext | castmethod 
-------+------------+------------+----------+-------------+------------
 10186 |         23 |       1560 |     1683 | e           | f
(1 row)

regression=# update pg_cast set castcontext = 'a' where castsource = 'integer'::regtype and casttarget = 'bit'::regtype;
UPDATE 1
regression=# select * from pg_cast where castsource = 'integer'::regtype and casttarget = 'bit'::regtype;
  oid  | castsource | casttarget | castfunc | castcontext | castmethod 
-------+------------+------------+----------+-------------+------------
 10186 |         23 |       1560 |     1683 | a           | f
(1 row)

regression=# insert into t values (1);
INSERT 0 1

The main disadvantage of this approach is you'd have to remember to
perform that UPDATE in any new database, since pg_dump wouldn't
preserve it for you.

On the whole though I think this project is a lost cause.  If you
are insisting on bug-compatibility with non-SQL-compliant details
of some other DBMS, and you can't adjust the application at all,
there is going to be some new showstopper problem biting you
every day.

			regards, tom lane

[1] https://www.postgresql.org/docs/current/catalog-pg-cast.html





view thread (6+ messages)  latest in thread

Message-ID: <1819966.1692278294@sss.pgh.pa.us>
Permalink:  ../1819966.1692278294@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1819966.1692278294@sss.pgh.pa.us

 · 

reply

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, karg@quipsy.de, ewie@ewie.name
  Subject: Re: Cast INTEGER to BIT confusion
  In-Reply-To: <1819966.1692278294@sss.pgh.pa.us>
  References: <fbc716336d544e93b6af5e11af3e4aa0@quipsy.de> <533487381.212078.1692100096551@office.mailbox.org> <84bd46dba5ec4097ba9663f46a1e5754@quipsy.de> <400164688.228966.1692109673749@office.mailbox.org> <015a3586e6dc40e0b1c3a4a1f3b1e44c@quipsy.de> <1819966.1692278294@sss.pgh.pa.us>

* 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