What Do I Do If Date Type Is Automatically Converted to the Timestamp Type During Table Creation?
When creating a database, you can set the DBCOMPATIBILITY parameter to the compatible database type. The value of DBCOMPATIBILITY can be ORA, TD, and MySQL, indicating Oracle, Teradata, and MySQL databases, respectively. If this parameter is not specified during database creation, the default value ORA is used. In ORA compatibility mode, the date type is automatically converted to timestamp(0). The date type is only supported in the MySQL compatibility mode.
To solve the problem, you need to change the compatibility mode to MySQL. The compatibility mode of an existing database cannot be changed. It can only be specified during creation of the database. GaussDB(DWS) supports the MySQL compatibility mode in cluster version 8.1.1 and later. To configure this mode, run the following commands:
1 2 3 4 5 6 7 8 9 |
gaussdb=> CREATE DATABASE mydatabase DBCOMPATIBILITY='mysql'; CREATE DATABASE gaussdb=> \c mydatabase Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "mydatabase" as user "dbadmin". mydatabase=> create table t1(c1 int, c2 date); NOTICE: The 'DISTRIBUTE BY' clause is not specified. Using round-robin as the distribution mode by default. HINT: Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column. CREATE TABLE |
If the problem cannot be solved by changing the compatibility, you can try to change the column type. For example, insert data of the date type as trings into a table. Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
gaussdb=> CREATE TABLE mytable (a date,b int); CREATE TABLE gaussdb=> INSERT INTO mytable VALUES(date '12-08-2023',01); INSERT 0 1 gaussdb=> SELECT * FROM mytable; a | b ---------------------+--- 2023-12-08 00:00:00 | 1 (1 row) gaussdb=> ALTER TABLE mytable MODIFY a VARCHAR(20); ALTER TABLE gaussdb=> INSERT INTO mytable VALUES('2023-12-10',02); INSERT 0 1 gaussdb=> SELECT * FROM mytable; a | b ---------------------+--- 2023-12-08 00:00:00 | 1 2023-12-10 | 2 (2 rows) |
Database Usage FAQs
- How Do I Change Distribution Columns?
- How Do I View and Set the Database Character Encoding?
- What Do I Do If Date Type Is Automatically Converted to the Timestamp Type During Table Creation?
- Do I Need to Run VACUUM FULL and ANALYZE on Common Tables Periodically?
- Do I Need to Set a Distribution Key After Setting a Primary Key?
- Is GaussDB(DWS) Compatible with PostgreSQL Stored Procedures?
- What Are Partitioned Tables, Partitions, and Partition Keys?
- How Can I Export the Table Structure?
- How Do I Delete Table Data Efficiently?
- How Do I View Foreign Table Information?
- If No Distribution Column Is Specified, How Will Data Be Stored?
- How Do I Replace the Null Result with 0?
- How Do I Check Whether a Table Is Row-Stored or Column-Stored?
- How Do I Query the Information About GaussDB(DWS) Column-Store Tables?
- Why Sometimes the GaussDB(DWS) Query Indexes Become Invalid?
- How Do I Use a User-Defined Function to Rewrite the CRC32() Function?
- What Are the Schemas Starting with pg_toast_temp* or pg_temp*?
- Solutions to Inconsistent GaussDB(DWS) Query Results
- Which System Catalogs That the VACUUM FULL Operation Cannot Be Performed on?
- In Which Scenarios Would a Statement Be "idle in transaction"?
- How Does GaussDB(DWS) Implement Row-to-Column and Column-to-Row Conversion?
- What Are the Differences Between Unique Constraints and Unique Indexes?
- What Are the Differences Between Functions and Stored Procedures?
- How Do I Delete Duplicate Table Data?
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbotmore