Skip to content

Conversation

hatyo
Copy link
Contributor

@hatyo hatyo commented Oct 10, 2025

With #3647 we introduce support for CAST operator, this adds documentation of this operator, including supported casts, error codes, and degree of compliance to the SQL standard.

This fixes #3662.

@hatyo hatyo added the documentation Documentation change label Oct 10, 2025
Copy link
Collaborator

@arnaud-lacurie arnaud-lacurie left a comment

Choose a reason for hiding this comment

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

Looks good overall!

I left a couple of comments.


.. code-block:: sql

CAST(expression AS target_type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

To remain consistent with the rest of the doc, you'd want to put a railroad diagram here.

The value or expression to be converted.

* :sql:`target_type`
The target data type. Can be a primitive type (:sql:`INT`, :sql:`LONG`, :sql:`FLOAT`, :sql:`DOUBLE`, :sql:`STRING`, :sql:`BOOLEAN`) or an array type (e.g., :sql:`INTEGER ARRAY`, :sql:`STRING ARRAY`).
Copy link
Collaborator

Choose a reason for hiding this comment

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

INT and LONG should be replaced by INTEGER and BIGINT throughout the document

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Boolean Conversions
-------------------

* :sql:`BOOLEAN` ↔ :sql:`INT`: true = 1, false = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably a uni-directional arrow, given the fact that the other direction is written the line underneath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, done.

INSERT INTO data VALUES (1, 'invalid')

SELECT CAST(str_value AS INTEGER) FROM data WHERE id = 1
-- Error: Cannot cast string 'invalid' to :sql:`INT`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that the actual error message?
I guess the error message should not contain :sql: since this is a RST thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the exact error message is: Value out of range for INT. There is something to be said about rewriting error messages originating from the Cascades types system validations and the upper relational layer SQL types., and overall consistency of SQL error messages, as in e.g. #3583.

@arnaud-lacurie
Copy link
Collaborator

Looks like you had a search replace mishap, can you fix that?

@hatyo
Copy link
Contributor Author

hatyo commented Oct 14, 2025

Looks like you had a search replace mishap, can you fix that?

You're right, I reverted the newly invented type floating poINTEGER back to floating point. Good observation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document CAST operator

2 participants