如何在Amazon Redshift中获取当前会话时区?设置时区后如何查看当前会话时区?
Hey there! Great question—you’re already close to what you need. Let’s break down how to check your current Redshift session timezone and get that query working exactly as you want:
There are a few straightforward ways to retrieve your active session timezone, and you can absolutely integrate this into the query structure you outlined:
1. Quick check with the SHOW command
The simplest way to get your current session timezone is to run this command directly:
SHOW TIMEZONE;
It’ll return a single value (like 'UTC' or 'CET') that reflects your session’s current timezone setting.
2. Use the CURRENT_TIMEZONE() function
You mentioned not finding this function, but it does exist in Redshift—just make sure to include the parentheses! You can use it in a SELECT statement like so:
SELECT CURRENT_TIMEZONE();
This outputs the same timezone string as the SHOW command.
3. Build your desired query
You can modify your sample query to include either CURRENT_TIMEZONE() or its alias SESSIONTIMEZONE to get the exact output format you’re expecting:
SELECT CURRENT_TIMEZONE() AS session_timezone, SYSDATE, SYSDATE::timestamptz, SYSDATE::timestamptz AT TIME ZONE 'UTC', SYSDATE::timestamptz AT TIME ZONE 'CET';
Or using the alias:
SELECT SESSIONTIMEZONE() AS session_timezone, SYSDATE, SYSDATE::timestamptz, SYSDATE::timestamptz AT TIME ZONE 'UTC', SYSDATE::timestamptz AT TIME ZONE 'CET';
After setting your timezone with SET TIMEZONE TO 'CET';, this query will return results matching the format you described, with the first column showing 'CET' as your session timezone.
Just a quick note: SESSIONTIMEZONE is an alias for CURRENT_TIMEZONE() in Redshift, so both work interchangeably.
内容的提问来源于stack exchange,提问作者RubenLaguna

