Skip to content

Commit 15cf504

Browse files
use getFieldFromColumnForASTLiteral for all types
1 parent d2fcd41 commit 15cf504

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Analyzer/ConstantNode.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,12 @@ QueryTreeNodePtr ConstantNode::cloneImpl() const
199199

200200
ASTPtr ConstantNode::toASTImpl(const ConvertToASTOptions & options) const
201201
{
202+
if (!options.add_cast_for_constants)
203+
return std::make_shared<ASTLiteral>(getFieldFromColumnForASTLiteral(constant_value.getColumn(), 0, constant_value.getType()));
204+
202205
const auto & constant_value_type = constant_value.getType();
203206
auto constant_value_ast = std::make_shared<ASTLiteral>(getValue());
204207

205-
if (!options.add_cast_for_constants)
206-
{
207-
if (WhichDataType(constant_value_type->getTypeId()).isDateTimeOrDateTime64())
208-
return std::make_shared<ASTLiteral>(getFieldFromColumnForASTLiteral(constant_value.getColumn(), 0, constant_value.getType()));
209-
return constant_value_ast;
210-
}
211-
212208
// Add cast if constant was created as a result of constant folding.
213209
// Constant folding may lead to type transformation and literal on shard
214210
// may have a different type.

tests/integration/test_storage_postgresql/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,12 @@ def test_postgres_datetime(started_cluster):
885885
result = node1.query("SELECT ts FROM test_datetime WHERE ts > '2025-01-01'::DateTime64")
886886
assert result == "2025-01-02 03:04:05.678900\n"
887887

888+
result = node1.query("SELECT ts FROM test_datetime WHERE ts > '2025-01-01'::Nullable(DateTime)")
889+
assert result == "2025-01-02 03:04:05.678900\n"
890+
891+
result = node1.query("SELECT ts FROM test_datetime WHERE ts > '2025-01-01'::Nullable(DateTime64)")
892+
assert result == "2025-01-02 03:04:05.678900\n"
893+
888894

889895
if __name__ == "__main__":
890896
cluster.start()

0 commit comments

Comments
 (0)