惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
U
Unit 42
GbyAI
GbyAI
M
MIT News - Artificial intelligence
美团技术团队
罗磊的独立博客
雷峰网
雷峰网
量子位
博客园 - 【当耐特】
Last Week in AI
Last Week in AI
D
Docker
小众软件
小众软件
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
WordPress大学
WordPress大学
V
V2EX
博客园_首页
腾讯CDC
The Cloudflare Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Time Zone Pitfall When Migrating from MySQL to GBase 8c —...
Michael · 2026-04-30 · via DEV Community

Michael

When moving from MySQL to GBase 8c, the China-domestically developed database from GBASE, time zone configuration can surprise you. What works perfectly in MySQL may yield results off by 16 hours in GBase 8c — all because of a simple sign reversal.

This article reproduces the issue, walks through the diagnosis, and gives you two clean solutions to keep your timestamps accurate in a gbase database environment.

The Problem

MySQL offers two common ways to set the time zone:

-- Offset notation
SET time_zone = '+08:00';

-- Named time zone
SET time_zone = 'Asia/Shanghai';

Enter fullscreen mode Exit fullscreen mode

Both work as expected.

Applying the same approach in GBase 8c, however, produces unexpected behavior:

swjtdb=# show timezone;
 TimeZone 
----------
 PRC
(1 row)

swjtdb=# select now();
       now()        
---------------------
 2025-10-19 22:23:18

swjtdb=# SET timezone = '+08:00';
SET

swjtdb=# select now();
       now()        
---------------------
 2025-10-19 06:23:39.868943-08  -- 16 hours behind

Enter fullscreen mode Exit fullscreen mode

Notice the offset is shown as -08 instead of +08, resulting in a 16-hour gap. Switching to a named zone like SET timezone = 'Asia/Shanghai' immediately corrects the display.

Diagnosis

Using AT TIME ZONE conversions reveals the root cause:

WITH test_times AS (
    SELECT '2025-10-19 12:00:00'::timestamptz as test_ts
)
SELECT 
    test_ts,
    test_ts AT TIME ZONE 'UTC' as as_utc,
    test_ts AT TIME ZONE '+08:00' as as_beijing,
    test_ts AT TIME ZONE '-08:00' as as_negative
FROM test_times;

Enter fullscreen mode Exit fullscreen mode

Result:

       test_ts         |       as_utc        |     as_beijing      |     as_negative     
------------------------+---------------------+---------------------+---------------------
 2025-10-19 12:00:00+08 | 2025-10-19 04:00:00 | 2025-10-18 20:00:00 | 2025-10-19 12:00:00 

Enter fullscreen mode Exit fullscreen mode

  • test_ts is noon Beijing time (+08)
  • AT TIME ZONE '+08:00' returns 8 PM the previous day, acting like UTC-8
  • AT TIME ZONE '-08:00' returns the correct noon

Confirming the sign flip:

SELECT 
    '2025-10-19 12:00:00'::timestamptz as base_time,
    ('2025-10-19 12:00:00'::timestamptz AT TIME ZONE '+08:00') as plus_eight,
    ('2025-10-19 12:00:00'::timestamptz AT TIME ZONE '-08:00') as minus_eight;

Enter fullscreen mode Exit fullscreen mode

Result:

      base_time        |     plus_eight      |     minus_eight     
------------------------+---------------------+---------------------
 2025-10-19 12:00:00+08 | 2025-10-18 20:00:00 | 2025-10-19 12:00:00 

Enter fullscreen mode Exit fullscreen mode

Key takeaway: In GBase 8c, +08:00 is interpreted as UTC-8, and -08:00 as UTC+8 — exactly the opposite of what many developers expect.

Solutions

Option 1: Simplified Numeric Syntax (Recommended)

GBase 8c accepts a signless number, which bypasses the inversion entirely:

SET timezone = '8';    -- cleanest
SET timezone = '08';   -- two-digit form

Enter fullscreen mode Exit fullscreen mode

For fractional offsets like +01:30, use a decimal:

SET timezone = '1.5';   -- equivalent to +01:30
-- or
SET timezone = '-01:30'; -- same effect but counter‑intuitive

Enter fullscreen mode Exit fullscreen mode

Verify:

SHOW TimeZone;  -- returns 08:00:00
SELECT now();   -- shows correct UTC+8 time

Enter fullscreen mode Exit fullscreen mode

Option 2: Named Time Zones (Standard Practice)

Named zones eliminate any ambiguity and are the safest choice across platforms:

SET timezone = 'Asia/Shanghai';
SET timezone = 'PRC';

-- List available time zones
SELECT name, utc_offset 
FROM pg_timezone_names 
WHERE utc_offset = '08:00:00'::interval;

Enter fullscreen mode Exit fullscreen mode

Best Practices

  • Prefer named zones: SET timezone = 'Asia/Shanghai' is self‑documenting and consistent.
  • Fallback to simplified numeric syntax: SET timezone = '8' avoids the sign‑flip trap.
  • Avoid ISO offset notation when migrating from MySQL: for East‑Eight, set -08:00, not +08:00 — which is the opposite of MySQL and of instinct.

After any time zone change, a quick SELECT now() is the simplest way to confirm correctness and prevent subtle data corruption when running a gbase database.