create type/cast/ENUM

本文介绍如何在PostgreSQL中使用枚举类型,并演示了创建枚举类型、使用枚举类型字段、定义枚举类型的默认值及范围查询等操作。此外,还详细解释了类型转换的过程,包括显式与隐式转换的实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

digoal=# CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TYPE
digoal=# CREATE TABLE person (
digoal(#     name text,
digoal(#     current_mood mood
digoal(# );
CREATE TABLE
digoal=# INSERT INTO person VALUES ('Moe', 'happy');
INSERT 0 1
digoal=# SELECT * FROM person;
 name | current_mood 
------+--------------
 Moe  | happy
(1 row)
digoal=# select enum_first(null::mood);   
 enum_first 
------------
 sad
(1 row)
digoal=# select enum_range('ok'::mood,null);   
 enum_range 
------------
 {ok,happy}
(1 row)



create cast: http://www.postgresql.org/docs/9.3/static/sql-createcast.htmlhttp://www.php100.com/manual/PostgreSQL8/sql-createcast.html

CREATE CAST (source_type AS target_type)
    WITH FUNCTION function_name (argument_type [, ...])
    [ AS ASSIGNMENT | AS IMPLICIT ]

CREATE CAST (source_type AS target_type)
    WITHOUT FUNCTION
    [ AS ASSIGNMENT | AS IMPLICIT ]

CREATE CAST (source_type AS target_type)
    WITH INOUT
    [ AS ASSIGNMENT | AS IMPLICIT ]
WITHOUT FUNCTION:
表示源数据类型和目标数据类型是二进制兼容的, 所以不需要什么函数来执行转换。
AS ASSIGNMENT:
表示转换可以在赋值环境里隐含调用。
AS IMPLICIT:
表示这个转换可以在任何环境里隐含调用。


digoal=# select cast(24 as text);
 text 
------
 24
(1 row)
digoal=# CREATE OR REPLACE FUNCTION increment(i integer) RETURNS text AS $$
digoal$#         BEGIN
digoal$#                 RETURN 'aaaaa'||i;
digoal$#         END;
digoal$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
digoal=# CREATE CAST (int AS text) WITH FUNCTION increment(int) AS ASSIGNMENT;                    
CREATE CAST
digoal=# select cast(24 as text);
  text   
---------
 aaaaa24
(1 row)
digoal=# drop cast (int as text);
DROP CAST
digoal=# select cast(24 as text);
 text 
------
 24
(1 row)
digoal=# select 2>=cast(24 as text)||''; 
ERROR:  operator does not exist: integer >= text
LINE 1: select 2>=cast(24 as text)||'';
                ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
digoal=# CREATE CAST (int AS text) WITH FUNCTION increment(int) AS IMPLICIT;
CREATE CAST
digoal=# select 2>=cast(24 as text)||'';                                    
 ?column? 
----------
 false
(1 row)


//11.应用属性到控件 face1->SetProperties(faceProps): lelete faceProps: class "NXOpen::BlockStyler::FaceCollector" 没有成员"SetProperties"参考以下文档:“#ifndef NXOpen_BLOCKSTYLER_FACECOLLECTOR_HXX_INCLUDED #define NXOpen_BLOCKSTYLER_FACECOLLECTOR_HXX_INCLUDED //-------------------------------------------------------------------------- // Header for C++ interface to JA API //-------------------------------------------------------------------------- // // Source File: // BlockStyler_FaceCollector.ja // // Generated by: // apiwrap // // WARNING: // This file is automatically generated - do not edit by hand // #ifdef _MSC_VER #pragma once #endif #include <NXOpen/NXDeprecation.hxx> #include <vector> #include <NXOpen/NXString.hxx> #include <NXOpen/Callback.hxx> #include <NXOpen/BlockStyler_UIBlock.hxx> #include <NXOpen/libnxopenuicpp_exports.hxx> #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable:4996) #endif #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif namespace NXOpen { namespace BlockStyler { class FaceCollector; } namespace BlockStyler { class UIBlock; } class TaggedObject; namespace BlockStyler { class _FaceCollectorBuilder; class FaceCollectorImpl; /** Represents a Face Collector <br> Created in NX8.5.0. <br> */ class NXOPENUICPPEXPORT FaceCollector : public NXOpen::BlockStyler::UIBlock { private: FaceCollectorImpl * m_facecollector_impl; private: friend class _FaceCollectorBuilder; protected: FaceCollector(); public: ~FaceCollector(); /**Returns the AutomaticProgression. If true, focus automatically progresses to the next selection block. <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: bool AutomaticProgression ( ); /**Sets the AutomaticProgression. If true, focus automatically progresses to the next selection block. <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetAutomaticProgression ( bool automaticProgression /** automaticprogression */ ); /**Returns the BalloonTooltipImage <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString BalloonTooltipImage ( ); /**Sets the BalloonTooltipImage <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetBalloonTooltipImage ( const NXString & imageString /** image string */ ); /**Sets the BalloonTooltipImage <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetBalloonTooltipImage ( const char * imageString /** image string */ ); /**Returns the BalloonTooltipLayout as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString BalloonTooltipLayoutAsString ( ); /**Sets the BalloonTooltipLayout as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetBalloonTooltipLayoutAsString ( const NXString & enumString /** enumstring */ ); /**Sets the BalloonTooltipLayout as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetBalloonTooltipLayoutAsString ( const char * enumString /** enumstring */ ); /** Gets the BalloonTooltipLayout members @return Value to get from the property. <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: std::vector<NXString> GetBalloonTooltipLayoutMembers ( ); /**Returns the BalloonTooltipText <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString BalloonTooltipText ( ); /**Sets the BalloonTooltipText <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetBalloonTooltipText ( const NXString & balloonTooltipText /** balloon tooltip text */ ); /**Sets the BalloonTooltipText <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetBalloonTooltipText ( const char * balloonTooltipText /** balloon tooltip text */ ); /**Returns the Bitmap <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString Bitmap ( ); /**Sets the Bitmap <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetBitmap ( const NXString & bitmapString /** bitmap string */ ); /**Sets the Bitmap <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetBitmap ( const char * bitmapString /** bitmap string */ ); /**Returns the BlendVirtualCurveOverlay <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: bool BlendVirtualCurveOverlay ( ); /**Sets the BlendVirtualCurveOverlay <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetBlendVirtualCurveOverlay ( bool blendCurve /** blendcurve */ ); /**Returns the FaceRules <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: int FaceRules ( ); /**Sets the FaceRules <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetFaceRules ( int faceRules /** facerules */ ); /**Returns the CreateInterpartLink <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: bool CreateInterpartLink ( ); /**Sets the CreateInterpartLink <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetCreateInterpartLink ( bool createLink /** createlink */ ); /**Returns the Cue <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString Cue ( ); /**Sets the Cue <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetCue ( const NXString & cue /** cue */ ); /**Sets the Cue <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetCue ( const char * cue /** cue */ ); /**Returns the InterpartSelection as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString InterpartSelectionAsString ( ); /**Sets the InterpartSelection as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetInterpartSelectionAsString ( const NXString & enumString /** enumstring */ ); /**Sets the InterpartSelection as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetInterpartSelectionAsString ( const char * enumString /** enumstring */ ); /** Gets the InterpartSelection members @return Value to get from the property <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: std::vector<NXString> GetInterpartSelectionMembers ( ); /** Gets the SelectedObjects @return Value to get from the property <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: std::vector<NXOpen::TaggedObject *> GetSelectedObjects ( ); /** Sets the SelectedObjects <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetSelectedObjects ( const std::vector<NXOpen::TaggedObject *> & objectVector /**Value to set for the property*/ ); /**Returns the SelectMode as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString SelectModeAsString ( ); /**Sets the SelectMode as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetSelectModeAsString ( const NXString & enumString /** enumstring */ ); /**Sets the SelectMode as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetSelectModeAsString ( const char * enumString /** enumstring */ ); /** Gets the SelectMode members @return Value to get from the property <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: std::vector<NXString> GetSelectModeMembers ( ); /**Returns the StepStatus as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString StepStatusAsString ( ); /**Sets the StepStatus as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetStepStatusAsString ( const NXString & enumString /** enumstring */ ); /**Sets the StepStatus as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetStepStatusAsString ( const char * enumString /** enumstring */ ); /** Gets the StepStatus members @return Value to get from the property <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: std::vector<NXString> GetStepStatusMembers ( ); /**Returns the ToolTip <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString ToolTip ( ); /**Sets the ToolTip <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetToolTip ( const NXString & toolTip /** tooltip */ ); /**Sets the ToolTip <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetToolTip ( const char * toolTip /** tooltip */ ); /**Returns the DefaultFaceRules as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString DefaultFaceRulesAsString ( ); /**Sets the DefaultFaceRules as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetDefaultFaceRulesAsString ( const NXString & enumString /** enumstring */ ); /**Sets the DefaultFaceRules as string <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetDefaultFaceRulesAsString ( const char * enumString /** enumstring */ ); /** Gets the DefaultFaceRules members @return Value to get from the property <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: std::vector<NXString> GetDefaultFaceRulesMembers ( ); /**Returns the EntityType <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: int EntityType ( ); /**Sets the EntityType <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetEntityType ( int entityType /** entitytype */ ); /**Returns the PopupMenuEnabled <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: bool PopupMenuEnabled ( ); /**Sets the PopupMenuEnabled <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetPopupMenuEnabled ( bool enabled /** enabled */ ); /**Returns the LabelString <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: NXString LabelString ( ); /**Sets the LabelString <br> Created in NX8.5.0. <br> <br> License requirements : None */ public: void SetLabelString ( const NXString & labelString /** labelstring */ ); /**Sets the LabelString <br> Created in NX8.5.0. <br> <br> License requirements : None */ void SetLabelString ( const char * labelString /** labelstring */ ); /**Returns the AllowConvergentObject <br> Created in NX11.0.0. <br> <br> License requirements : None */ public: bool AllowConvergentObject ( ); /**Sets the AllowConvergentObject <br> Created in NX11.0.0. <br> <br> License requirements : None */ public: void SetAllowConvergentObject ( bool allowConvergentObject /** allowconvergentobject */ ); /**Returns the MaximumScope <br> Created in NX11.0.0. <br> <br> License requirements : None */ public: NXString MaximumScopeAsString ( ); /**Sets the MaximumScope <br> Created in NX11.0.0. <br> <br> License requirements : None */ public: void SetMaximumScopeAsString ( const NXString & enumString /** enumstring */ ); /**Sets the MaximumScope <br> Created in NX11.0.0. <br> <br> License requirements : None */ void SetMaximumScopeAsString ( const char * enumString /** enumstring */ ); }; } } #ifdef _MSC_VER #pragma warning(pop) #endif #ifdef __GNUC__ #ifndef NX_NO_GCC_DEPRECATION_WARNINGS #pragma GCC diagnostic warning "-Wdeprecated-declarations" #endif #endif #undef EXPORTLIBRARY #endif ”
最新发布
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值