Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oVY8v-00071F-EL for pgsql-general@arkaria.postgresql.org; Tue, 06 Sep 2022 12:57:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oVY8u-00055c-9l for pgsql-general@arkaria.postgresql.org; Tue, 06 Sep 2022 12:57:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oVY8t-00055T-Tn for pgsql-general@lists.postgresql.org; Tue, 06 Sep 2022 12:57:27 +0000 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oVY8r-0007cB-C8 for pgsql-general@lists.postgresql.org; Tue, 06 Sep 2022 12:57:26 +0000 Received: by mail-qk1-x732.google.com with SMTP id a10so7986574qkl.13 for ; Tue, 06 Sep 2022 05:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date; bh=hv5wiisrQ02kDtXfGmoMrJEzNjmzi3sEp1bi6VVuI6c=; b=n1tlU0oeC0Du3s8ncuDe1GO8IHdPs7OAJaibiBitNTBel+07UF+VmkoG4xMUiEn4tT EBs0GRJJBbcg12kZs5tMJ+6hTvmaBuInx+alRKS9Q+6fEH6qo/A1/54YHW9fdSA5r9IS kIoG1PZg1g68rNv2FmZ4MGsz1Ikk3cgztfHndB67HM7NmDff1/s0mYwcEMPpm05rlgvY +A4nLPOmlmqdc+Gpx9Qd/Y1s61zRR1cFh3L6vEsXzbFxObURezrqWbWT+ZdTRUwxdxDd MBpkOGKtXZx/4LpLgg7fKHmFwneeJ4keGPgq6O0nYs/9z2INd+uhzAvjqSNME9i6ujQd aJlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date; bh=hv5wiisrQ02kDtXfGmoMrJEzNjmzi3sEp1bi6VVuI6c=; b=f21HwNeZ+n99JWGzkg8NF7jyW+qByD+iI0D3NanS9qGGTk721J3KtB3pqFvGTFhndN AvlHbEf/Z4TgcU3UwhB5zMxwgDLv9D2t9avqxk7ymcy6HEvIL3QTQDGkLoDWxnwx1v8p YgFihUMGtrtsKBFa1UDBL2pf6i5DXc44rvg7n1kTWlWiFyScfAXOpymwX1yogz0Oc832 RQSCPlLJ7Tp/3puCuZ5VLSLSZArZYBLiKq3DslulmWn7s7V0500BKvYttzI4sA91aLuX 1iAOSRqo0RusWlPsJyNQoOQQn4zDO051nemWr0DuZu0TD8pU+2y2wmvx6Ry5Mjc6gt/N 19Eg== X-Gm-Message-State: ACgBeo0Q8d1LlmLfqyq7lTvR4JvFGUi75WNJNrhDw3yyxdDijJjN4xv6 AenVHyy4s7FRIhakgY4Gm+aqvEK5qWks9txZ X-Google-Smtp-Source: AA6agR4psJn6cGRuCawkdW31lGabWoMI6gru5t7F1rjrPsvUuA4//G7oAGJLhX4mpllVrkpRPTsIQQ== X-Received: by 2002:a05:620a:4590:b0:6bb:82c7:8cf0 with SMTP id bp16-20020a05620a459000b006bb82c78cf0mr35134307qkb.380.1662469044214; Tue, 06 Sep 2022 05:57:24 -0700 (PDT) Received: from [192.168.2.100] (pool-72-79-30-4.nwrknj.east.verizon.net. [72.79.30.4]) by smtp.gmail.com with ESMTPSA id do35-20020a05620a2b2300b006b8d1914504sm11642285qkb.22.2022.09.06.05.57.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Sep 2022 05:57:23 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------KVERPVN1k7jVmiW7uzTbZmTw" Message-ID: Date: Tue, 6 Sep 2022 08:57:23 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: Postgres SQL unable to handle Null values for Text datatype To: pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Mladen Gogala In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------KVERPVN1k7jVmiW7uzTbZmTw Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 9/6/22 02:10, Karthik K L V wrote: > We are migrating from Oracle 12C to Aurora Postgres 13 and running > into query failures when the bind value of a Text datatype resolves to nul Oracle is actually in the wrong here. Nothing should be equal to null, ever. There is also different behavior with unique indexes: [mgogala@umajor ~]$ docker start psql14-5 psql14-5 [mgogala@umajor ~]$ psql -U scott Password for user scott: psql (14.5) Type "help" for help. scott=> create table test1 (key1 integer,key2 integer, data varchar(10)); CREATE TABLE scott=> alter table test1 add constraint test1_uq unique(key1,key2); ALTER TABLE scott=> insert into test1 values(1,null,'aaaaa'); INSERT 0 1 scott=> insert into test1 values(1,null,'bbbbb'); INSERT 0 1 scott=> select * from test1;  key1 | key2 | data ------+------+-------     1 |      | aaaaa     1 |      | bbbbb (2 rows) The same thing would not work with Oracle. However, please note that, according to SQL standard, NULL is not equal to anything, to those 2 rows are actually not a unique constraint violation. To enforce the uniqueness the same way as with Oracle, you actually need 2 indexes.  You need to use the "coalesce" function. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com --------------KVERPVN1k7jVmiW7uzTbZmTw Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 9/6/22 02:10, Karthik K L V wrote:
We are migrating from Oracle 12C to Aurora Postgres 13 and running into query failures when the bind value of a Text datatype resolves to nul

Oracle is actually in the wrong here. Nothing should be equal to null, ever. There is also different behavior with unique indexes:

[mgogala@umajor ~]$ docker start psql14-5
psql14-5
[mgogala@umajor ~]$ psql -U scott
Password for user scott:
psql (14.5)
Type "help" for help.

scott=> create table test1 (key1 integer,key2 integer, data varchar(10));
CREATE TABLE
scott=> alter table test1 add constraint test1_uq unique(key1,key2);
ALTER TABLE
scott=> insert into test1 values(1,null,'aaaaa');
INSERT 0 1
scott=> insert into test1 values(1,null,'bbbbb');
INSERT 0 1
scott=> select * from test1;
 key1 | key2 | data  
------+------+-------
    1 |      | aaaaa
    1 |      | bbbbb
(2 rows)

The same thing would not work with Oracle. However, please note that, according to SQL standard, NULL is not equal to anything, to those 2 rows are actually not a unique constraint violation. To enforce the uniqueness the same way as with Oracle, you actually need 2 indexes.  You need to use the "coalesce" function.

-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
--------------KVERPVN1k7jVmiW7uzTbZmTw--