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

Postgres inconsistency: array_agg(pg_typeof(...)) in pg flattens result #27150

Open
Tracked by #21981
nrainer-materialize opened this issue May 17, 2024 · 0 comments
Open
Tracked by #21981

Comments

@nrainer-materialize
Copy link
Contributor

nrainer-materialize commented May 17, 2024

Likely not a bug in mz but a strange behavior in pg.

Given

DROP TABLE IF EXISTS evaluation;
CREATE TABLE evaluation (row_index INT, decimal_39_8_val DECIMAL(39,8));
INSERT INTO evaluation VALUES (10, 0.99999999::DECIMAL(39,8));
SELECT array_agg(pg_typeof(decimal_39_8_val) ORDER BY row_index) FROM evaluation;

produces

  • in mz: a row with a column with value ['numeric'] of type text list
  • in pg: a row with a column with value '{numeric}' of type string

The behavior of pg seems a bit special here. When querying array_agg(decimal_39_8_val), pg will also return a list.

More details

Given

        x1 = self.executor.query("SELECT array_agg(pg_typeof(decimal_39_8_val) ORDER BY row_index) FROM t_dfr_vert WHERE (row_index IN (10));")
        x2 = self.executor.query("SELECT array_agg(pg_typeof(decimal_39_8_val) ORDER BY row_index) FROM t_dfr_vert WHERE (row_index IN (7,8,10));")
        x3 = self.executor.query("SELECT array_agg(decimal_39_8_val ORDER BY row_index) FROM t_dfr_vert WHERE (row_index IN (7,8,10));")
        x4 = self.executor.query("SELECT array_agg(text_val ORDER BY row_index) FROM t_dfr_vert WHERE (row_index IN (7,8,10));")

fetching from mz and

        y1 = self.pg_executor.query("SELECT array_agg(pg_typeof(decimal_39_8_val) ORDER BY row_index) FROM t_pg_vert WHERE (row_index IN (10));")
        y2 = self.pg_executor.query("SELECT array_agg(pg_typeof(decimal_39_8_val) ORDER BY row_index) FROM t_pg_vert WHERE (row_index IN (7,8, 10));")
        y3 = self.pg_executor.query("SELECT array_agg(decimal_39_8_val ORDER BY row_index) FROM t_pg_vert WHERE (row_index IN (7,8, 10));")
        y4 = self.pg_executor.query("SELECT array_agg(text_val ORDER BY row_index) FROM t_pg_vert WHERE (row_index IN (7,8, 10));")

fetching from Postgres, results are:

x1 = {tuple: 1} ([['numeric']],)
x2 = {tuple: 1} ([['numeric', 'numeric', 'numeric']],)
x3 = {tuple: 1} ([[Decimal('0.49999999'), Decimal('0.50000001'), Decimal('1.00000001')]],)
x4 = {tuple: 1} ([['ff00aa', ' mAA m\n\t ', 'a']],)
y1 = {tuple: 1} (['{numeric}'],)
y2 = {tuple: 1} (['{numeric,numeric,numeric}'],)
y3 = {tuple: 1} ([[Decimal('0.49999999'), Decimal('0.50000001'), Decimal('1.00000001')]],)
y4 = {tuple: 1} ([['ff00aa', ' mAA m\n\t ', 'a']],)

x1 differs from y1 and x2 differs from y2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant