Skip to content

Fix views when CAST NULL#75

Merged
bhvkshah merged 1 commit intoaws:masterfrom
ssheikin:ssheikin/varchar_-5_length
Dec 14, 2022
Merged

Fix views when CAST NULL#75
bhvkshah merged 1 commit intoaws:masterfrom
ssheikin:ssheikin/varchar_-5_length

Conversation

@ssheikin
Copy link
Copy Markdown
Contributor

Redshift JDBC driver returns Invalid VARCHAR length -5 for column type during select from view created as:

CREATE VIEW test_view AS SELECT CAST(NULL AS CHARACTER VARYING) AS value

According to Postgres documentation:
atttypmod int4
atttypmod records type-specific data supplied at table creation time (for example, the maximum length of a varchar column). It is passed to type-specific input functions and length coercion functions. The value will generally be -1 for types that do not need atttypmod.

Seems Redshift JDBC driver uses that in a wrong way - atttypmod is not applicable for null.

Description

Fix not possible length for varchar.

Motivation and Context

Testing

CREATE VIEW test_view AS SELECT CAST(NULL AS CHARACTER VARYING) AS value;

select * from test_view;

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG

License

  • By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Redshift JDBC driver returns `Invalid VARCHAR length -5` for column type
during select from view created as:
```
CREATE VIEW test_view AS SELECT CAST(NULL AS CHARACTER VARYING) AS value
```

According to Postgres documentation:
`atttypmod int4`
atttypmod records type-specific data supplied at table creation time
(for example, the maximum length of a varchar column). It is passed to
type-specific input functions and length coercion functions.
The value will generally be -1 for types that do not need atttypmod.

Seems Redshift JDBC driver uses that in a wrong way -
atttypmod is not applicable for null.
@ssheikin
Copy link
Copy Markdown
Contributor Author

ssheikin commented Dec 5, 2022

@bhvkshah @Brooke-white @iggarish @hyandell Could you please take a look on this PR?

@bhvkshah
Copy link
Copy Markdown
Contributor

bhvkshah commented Dec 5, 2022

@ssheikin will have an update for you once I've reviewed your changes. Thank you for the PR!

@wendigo
Copy link
Copy Markdown

wendigo commented Dec 12, 2022

@bhvkshah any update on that PR?

@bhvkshah bhvkshah self-requested a review December 14, 2022 19:54
@Brooke-white Brooke-white self-requested a review December 14, 2022 20:02
Copy link
Copy Markdown
Contributor

@Brooke-white Brooke-white left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @ssheikin ! looks good :)

@bhvkshah bhvkshah merged commit 4719c41 into aws:master Dec 14, 2022
@ssheikin
Copy link
Copy Markdown
Contributor Author

Thank you @Brooke-white @bhvkshah for merging!
When we can expect the new release with the fix?

findinpath added a commit to findinpath/trino that referenced this pull request Mar 13, 2023
Corresponding pr to Redshift JDBC driver:
aws/amazon-redshift-jdbc-driver#75

Co-authored-by: Sasha Sheikin <myminitrue@gmail.com>
ebyhr pushed a commit to trinodb/trino that referenced this pull request Mar 13, 2023
Corresponding pr to Redshift JDBC driver:
aws/amazon-redshift-jdbc-driver#75

Co-authored-by: Sasha Sheikin <myminitrue@gmail.com>
@ssheikin ssheikin deleted the ssheikin/varchar_-5_length branch November 26, 2023 22:57
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

Successfully merging this pull request may close these issues.

4 participants