当前位置:网站首页>Data type classification supported by postgre SQL

Data type classification supported by postgre SQL

2022-06-21 12:36:00 2022 Chongya

CAST  Data type conversion function

Boolean type :
        Supporting the standard boolean data type   Only TRUE FALSE Two kinds of state , If unknown state , Then use NULL Express
data type :
        smalint(2 byte ): oracle There is no such type , Use number Instead of
        int(4 byte )   bigint(8 byte )   
        numeric( Decimal exact type ): User declared precision , stay ORACLE called NUMBER
        real、double、precision( Floating point type )
        money( Type of currency )
Character type :varchar(n)、char(n)、test Three types of
Binary data type : There is only one bytea, He corresponds to mysql in BLOB And LONGBLOB,oracle Medium raw Type can be used bytea replace
        A binary string is a sequence of bytes . The difference between it and ordinary strings :
        (1) It is possible to store byte zero values , Normal strings do not allow byte zero values to be stored
        (2) Handle binary strings , Actually handle bytes ; Handling of strings , Depends on the locale
         
Bit string type : a string 0 and 1 String , Yes bit(n)、bit varying(n) Two kinds of   Other databases do not have this type
Date and time :date、time、timestamp. and time and timestamp Whether two types of time zones are included
         Date input : Any date or time text entry needs to be made by “ date / Time ” Type a single quoted string
         If DateStyle The parameter defaults to “MDY” , According to “ month - Japan - year ” analysis
         Set date type : set datestyle='YMD';
 
Enumeration type : A data type that contains an ordered collection of static values , And MYSQL Different , Required before use ctreate type Create type , Equal to... In some programming languages enum type
         Each enumeration type is independent , Cannot be mixed with other enumeration types ; Enumeration types are case sensitive .
         eg: So let's set up a “week" Enumerated type of , And create a test table :
         create type week as  ENUM('Sun','Mon','Thur','Fri','Sat');
         create table duty(person text,weekday week);
         insert into duty values(' Zhang San ','Sun');
         insert into duty values(' Li Si ','Mon');
         insert into duty values(' The king 2 ','Tues');
         insert into duty values(' Zhao Wu ','Wed');
         Try to query a piece of data :
         select * from duty where weekday = 'Sun';
         But if the input string no longer enumerates between types , You're going to report a mistake :
         select * from duty where weekday = 'Sun.';
         stay plsql in , have access to \dT View the definition of enumeration type :
         \dT+ week
         Direct query table pg_enum You can view the definition of enumeration types ;
         select  * from pg_enum;
    
The compound type : Combine existing simple types into user-defined types , for example C Structure in language , It is similar to selecting a field from a table name , Use parentheses to avoid SQL Parser obfuscation
         eg:
         select person_info.name from author;  (x)
         select (person_info).name from author;
         

xml type : Storage XML data type . The string type can also be used to store XML data , but test Type does not guarantee that the storage in it is legal XML data .

Postgre Dealing with character sets , When transferring data between the client and the server , Character set conversion will be performed automatically , If the character sets at both ends are inconsistent , Character set conversion will be performed automatically      
    
JSON type : Storage JSON(JavaScript Object Notion) Type data , You can also use text、varchar And other types of storage JSON type {
      JSON Type is to input the output data into the database intact , It will be checked before storage JSON Type for syntax checking , You need to re parse the data when using ; stay JSON In a string key Extra space between 、 repeat key Values are also retained
      JSONB When the type is stored, it will be resolved to binary type ; And supports indexing on it ,JSONB Higher performance in use

When one JSON The string is converted to JSONB type ,JSON The string data type is actually converted to PostgreSQL Database type

range: Storage range quick search data , Used to indicate a range
       create table ipdb1(
         ip_begin inet,
         ip_end inet,
         area text,
         sp text);
       
      
Object identifier type :oid 、regproc、regclass type
Pseudo type : Cannot be a field data type 、 But it can be used as a declaration letter s Number parameter or result type
Other types : Some types that are not easy to classify ; for example UUID、pg_lsn type

 

      

原网站

版权声明
本文为[2022 Chongya]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211230058307.html