Support PostgreSQL array created using array internal type name#659
Conversation
22731d2 to
9d40b66
Compare
|
@guyco33 i checked in Postgres 11.2 and confirmed your findings: However
|
|
@guyco33 for now, let's get #668 in. let's discuss whether we need this change or not. But maybe there is something newer that I should refer to? |
@findepi Maybe |
I think that our main motivation should be to map all Postgres array columns although they might be created with native names - I guess that there are plenty of automated tools that construct Postgres tables from their native names and we might loose them without this change (I encountered lots of Postgres sources with such tables)
From https://www.postgresql.org/docs/11/catalog-pg-attribute.html we can learn that |
|
I asked for clarification on PostgreSQL user group https://www.postgresql.org/message-id/CAMrFzbt_DjD1BSLOhAUgNApu8MV3CCPmbEac9FfMxOOq6GAD0g%40mail.gmail.com |
|
And here's the response: https://www.postgresql.org/message-id/31659.1556226223%40sss.pgh.pa.us |
|
And a follow up: https://www.postgresql.org/message-id/32678.1556228173%40sss.pgh.pa.us In particular:
I therefore propose that we go with #682 |
findepi
left a comment
There was a problem hiding this comment.
Now that we agreed to the way forward in #682 (comment), I feel this is a good change -- let's treat arrays with undeclared dimensions as single-dimension arrays.
I have some review comments.
Also, please rebase to accommodate for my #687.
Please change the commit message to something like
Support PostgreSQL array created using array internal type name
There was a problem hiding this comment.
Would this be following be enough
| "AND CASE WHEN att.attndims = 0 AND attyp.typcategory = 'A' THEN 1 ELSE att.attndims END > 0 "; | |
| "AND attyp.typcategory = 'A' "; |
(if not sufficient, then this should be AND (attyp.typcategory = 'A' OR att.attndims > 0), but I would strongly not have such an OR until I understand why one would be needed)
?
There was a problem hiding this comment.
Seems that your suggestion is sufficient unless there are cases that attndims is NULL.
Anyway, selecting COALESCE(att.attndims,1) will cover this as well.
There was a problem hiding this comment.
Would that work?
| "SELECT att.attname, CASE WHEN att.attndims = 0 AND attyp.typcategory = 'A' THEN 1 ELSE att.attndims END AS attndims " + | |
| "SELECT att.attname, max(att.attndims, 1) " + |
There was a problem hiding this comment.
Should be greatest(att.attndims, 1)
There was a problem hiding this comment.
Please rebase. You will need to remove testInternalArray.
There was a problem hiding this comment.
Use DataTypeTest with arrayDataType(integerDataType(), "_int4")
There was a problem hiding this comment.
Is there away to use DataTypeTest with a predefined table?
_int4 can't be created by CTAS from presto.
There was a problem hiding this comment.
Please see how TestPostgreSqlTypeMapping#postgresCreateAndInsert is used. When using this method, the table is created and populated directly in PostgreSQL.
9d40b66 to
bd6c8c0
Compare
bd6c8c0 to
c9e057a
Compare
|
Merged, thanks! |
Fixing failure when selecting Postgres Array column that was created with native type name (eg: _int4)
Postgres:
create table t (a _int4);Presto:
select a from t;Explanation:
pg_attribute.attndimsis 0 when creating columns with the native type namescreate table t (a _int4); --> pg_attribute.attndims = 0 for column acreate table t (a int[]); --> pg_attribute.attndims = 1 for column aFix potential issue for #317