Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different display format for array/struct with pg #4769

Closed
xxchan opened this issue Aug 21, 2022 · 2 comments · Fixed by #6019 or #13229
Closed

Different display format for array/struct with pg #4769

xxchan opened this issue Aug 21, 2022 · 2 comments · Fixed by #6019 or #13229
Assignees
Labels
component/common Common components, such as array, data chunk, expression. difficulty/medium Issues that need some knowledge of the whole system good first issue Good for newcomers type/enhancement Improvements to existing implementation. user-facing-changes Contains changes that are visible to users
Milestone

Comments

@xxchan
Copy link
Member

xxchan commented Aug 21, 2022

In PG, strings with spaces and empty string are displayed with ""

postgres=# select ARRAY['1','','2'];
  array
----------
 {1,"",2}
(1 row)

postgres=# select ARRAY['1',' ','2'];
   array
-----------
 {1," ",2}
(1 row)

postgres=# select ARRAY['1','1 1','2'];
    array
-------------
 {1,"1 1",2}
(1 row)

postgres=# select ARRAY['1',' 1 ','2'];
    array
-------------
 {1," 1 ",2}
(1 row)

In risingwave:

dev=> select ARRAY['1','','2'];
 ?column?
----------
 {1,,2}
(1 row)

dev=> select ARRAY['1',' ','2'];
 ?column?
----------
 {1, ,2}
(1 row)

dev=> select ARRAY['1','1 1','2'];
 ?column?
-----------
 {1,1 1,2}
(1 row)

dev=> select ARRAY['1',' 1 ','2'];
 ?column?
-----------
 {1, 1 ,2}
(1 row)

Do we want to follow this behavior?

@xxchan xxchan added type/bug Something isn't working type/enhancement Improvements to existing implementation. and removed type/bug Something isn't working labels Aug 21, 2022
@fuyufjh fuyufjh added the good first issue Good for newcomers label Aug 23, 2022
@fuyufjh fuyufjh added this to the release-0.1.13 milestone Aug 31, 2022
@skyzh skyzh added component/common Common components, such as array, data chunk, expression. event/OSD labels Sep 2, 2022
@xiangjinwu xiangjinwu self-assigned this Sep 5, 2022
@skyzh skyzh added difficulty/medium Issues that need some knowledge of the whole system and removed event/OSD labels Sep 16, 2022
@mergify mergify bot closed this as completed in #6019 Oct 25, 2022
@xiangjinwu xiangjinwu changed the title Different display format for string array with pg Different display format for array/struct with pg Oct 25, 2022
@xiangjinwu xiangjinwu reopened this Oct 25, 2022
@xiangjinwu
Copy link
Contributor

There are more differences to fix.

Background: In PostgreSQL, boolean is shown differently when displayed as output (boolout) and when casted to string (booltext):

test=# select true;
 bool 
------
 t
(1 row)

test=# select true::varchar;
 varchar 
---------
 true
(1 row)

When inside array or struct, it should use the shorter output:
Expected (PostgreSQL):

test=# select array[true];
 array 
-------
 {t}
(1 row)

test=# select array[true]::varchar;
 array 
-------
 {t}
(1 row)

test=# select row(true);
 row 
-----
 (t)
(1 row)

test=# select row(true)::varchar;
 row 
-----
 (t)
(1 row)

Actual (RisingWave):

dev=> select array[true];
 ?column? 
----------
 {true}
(1 row)

Another issue is the output of timestamp with time zone, which shares Scalar::Int64 as physical in-memory representation:
Expected (PostgreSQL):

test=# set timezone to utc;
SET
test=# select '2022-10-01 12:00:00+01:00'::timestamptz;
      timestamptz       
------------------------
 2022-10-01 11:00:00+00
(1 row)

test=# select array['2022-10-01 12:00:00+01:00'::timestamptz];
           array            
----------------------------
 {"2022-10-01 11:00:00+00"}
(1 row)

Actual (RisingWave):

dev=> select '2022-10-01 12:00:00+01:00'::timestamptz;
         ?column?          
---------------------------
 2022-10-01 11:00:00+00:00
(1 row)

dev=> select array['2022-10-01 12:00:00+01:00'::timestamptz];
      ?column?      
--------------------
 {1664622000000000}
(1 row)

Moreover, PostgreSQL also shows null differently in different context:

test=# select null;
 ?column? 
----------
 
(1 row)

test=# select null::varchar;
 varchar 
---------
 
(1 row)

test=# select array[null];
 array  
--------
 {NULL}
(1 row)

test=# select row(null);
 row 
-----
 ()
(1 row)

test=# select row();
 row 
-----
 ()
(1 row)

test=# select row(null,null);
 row 
-----
 (,)
(1 row)

But in RisingWave:

dev=> select row(null);
 ?column? 
----------
 (NULL)
(1 row)

Last thing: the quoting should also be considered when outputting a struct, and when casting from a string to an array or struct:

test=# select row('nULl','',' a b ',',');
          row          
-----------------------
 (nULl,""," a b ",",")
(1 row)

test=# select unnest('{NULL,"nULl",""," a b ",","}'::varchar[]);
 unnest 
--------
 
 nULl
 
  a b 
 ,
(5 rows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/common Common components, such as array, data chunk, expression. difficulty/medium Issues that need some knowledge of the whole system good first issue Good for newcomers type/enhancement Improvements to existing implementation. user-facing-changes Contains changes that are visible to users
Projects
None yet
5 participants