duckdb-web
                                
                                 duckdb-web copied to clipboard
                                
                                    duckdb-web copied to clipboard
                            
                            
                            
                        Issue found on page 'Set Operations'
Page URL: https://duckdb.org/docs/sql/query_syntax/setops#union
The documentation under UNION states:
 The UNION clause can be used to combine rows from multiple queries. The queries are required to have the same number of columns and the same column types.
- This seems to imply that if the column types are not the same an error would occur as DuckDB does error on a difference in the number of columns.
Under the Set Operations it states:
 If the columns are not of the same type, casts may be added.
- Which is happening in my example below, but the UNION documentation that followed seems to counteract this statement.
Example: When replicating a PostgreSQL query, if I have one column as VARCHAR and one column as BIGINT and I perform a UNION of these columns using DuckDB the resulting output type is a VARCHAR, with PostgreSQL this generates an error.
Originally, I thought this was possibly a bug, but found the following discussion which is apparently the intended behaviour.
I believe the documentation should be updated to reflect that an implicit cast could occur if the column types are not the same under the UNION heading.
I wasn't able to find a way to get the same behaviour as PostgreSQL and if there is a way it would be nice if this could be documented.