@@ -808,7 +808,13 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over
808
808
809
809
columnMeta.SetDefaultFromLiteral ();
810
810
811
- if (auto pgConst = constraint.Value ().Maybe <TCoPgConst>()) {
811
+ YQL_ENSURE (constraint.Value ().IsValid ());
812
+ const auto & constrValue = constraint.Value ().Cast ();
813
+ bool isPgNull = constrValue.Ptr ()->IsCallable () &&
814
+ constrValue.Ptr ()->Content () == " PgCast" && constrValue.Ptr ()->ChildrenSize () >= 1 &&
815
+ constrValue.Ptr ()->Child (0 )->IsCallable () && constrValue.Ptr ()->Child (0 )->Content () == " Null" ;
816
+
817
+ if (constrValue.Maybe <TCoPgConst>() || isPgNull) {
812
818
auto actualPgType = actualType->Cast <TPgExprType>();
813
819
YQL_ENSURE (actualPgType);
814
820
@@ -819,25 +825,31 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over
819
825
return TStatus::Error;
820
826
}
821
827
822
- TString content = TString (pgConst.Cast ().Value ().Value ());
823
- auto parseResult = NKikimr::NPg::PgNativeBinaryFromNativeText (content, typeDesc);
824
- if (parseResult.Error ) {
825
- ctx.AddError (TIssue (ctx.GetPosition (constraint.Pos ()),
826
- TStringBuilder () << " Failed to parse default expr for typename " << actualPgType->GetName ()
827
- << " , error reason: " << *parseResult.Error ));
828
- return TStatus::Error;
828
+ if (isPgNull) {
829
+ columnMeta.DefaultFromLiteral .mutable_value ()->set_null_flag_value (NProtoBuf::NULL_VALUE);
830
+ } else {
831
+ YQL_ENSURE (constrValue.Maybe <TCoPgConst>());
832
+ auto pgConst = constrValue.Cast <TCoPgConst>();
833
+ TString content = TString (pgConst.Value ().Value ());
834
+ auto parseResult = NKikimr::NPg::PgNativeBinaryFromNativeText (content, typeDesc);
835
+ if (parseResult.Error ) {
836
+ ctx.AddError (TIssue (ctx.GetPosition (constraint.Pos ()),
837
+ TStringBuilder () << " Failed to parse default expr for typename " << actualPgType->GetName ()
838
+ << " , error reason: " << *parseResult.Error ));
839
+ return TStatus::Error;
840
+ }
841
+
842
+ columnMeta.DefaultFromLiteral .mutable_value ()->set_bytes_value (parseResult.Str );
829
843
}
830
844
831
- columnMeta.DefaultFromLiteral .mutable_value ()->set_bytes_value (parseResult.Str );
832
845
auto * pg = columnMeta.DefaultFromLiteral .mutable_type ()->mutable_pg_type ();
833
-
834
846
pg->set_type_name (NKikimr::NPg::PgTypeNameFromTypeDesc (typeDesc));
835
847
pg->set_oid (NKikimr::NPg::PgTypeIdFromTypeDesc (typeDesc));
836
- } else if (auto literal = constraint. Value () .Maybe <TCoDataCtor>()) {
837
- FillLiteralProto (constraint. Value (). Cast <TCoDataCtor> (), columnMeta.DefaultFromLiteral );
848
+ } else if (auto literal = constrValue .Maybe <TCoDataCtor>()) {
849
+ FillLiteralProto (literal. Cast (), columnMeta.DefaultFromLiteral );
838
850
} else {
839
851
ctx.AddError (TIssue (ctx.GetPosition (constraint.Pos ()),
840
- TStringBuilder () << " Unsupported type of default value " << constraint. Value (). Cast (). Ptr ()-> Content () ));
852
+ TStringBuilder () << " Unsupported type of default value" ));
841
853
return TStatus::Error;
842
854
}
843
855
0 commit comments