From b58c985bdb2a9b6a2c232a425914b462a33a05cc Mon Sep 17 00:00:00 2001 From: Mikhail Bautin Date: Sat, 10 Nov 2018 09:37:31 -0800 Subject: [PATCH] [#566] Enable TIMESTAMP type in PostgreSQL; fix float test on ASAN by disabling UBSAN on float.c Summary: Enable TIMESTAMP type in PostgreSQL. The serialization format is a 64-bit integer. Also fix `yb_float4` and `yb_float8` tests on ASAN by disabling UBSAN in `float.c`. PostgreSQL test framework improvement: display a human-readable side-by-side diff with line numbers specified separately on each side. Example: http://bit.ly/2QuYYuO This commit fixes #566. Test Plan: Jenkins Reviewers: neil, robert, mihnea Reviewed By: mihnea Subscribers: bharat, yql Differential Revision: https://phabricator.dev.yugabyte.com/D5687 --- .../compiler-wrappers/compiler-wrapper.sh | 26 +- .../test/java/org/yb/client/TestUtils.java | 15 + .../yb/minicluster/BaseMiniClusterTest.java | 31 +- .../org/yb/minicluster/MiniYBCluster.java | 11 +- .../yb/minicluster/MiniYBClusterBuilder.java | 11 +- .../java/org/yb/minicluster/MiniYBDaemon.java | 8 +- .../test/java/org/yb/util/CommandResult.java | 13 +- .../test/java/org/yb/util/SanitizerUtil.java | 6 +- .../test/java/org/yb/util/SideBySideDiff.java | 228 +++ .../src/test/java/org/yb/util/StringUtil.java | 23 + .../org/yb/cql/TestConsistencyLevels.java | 17 +- .../java/org/yb/pgsql/PgRegressRunner.java | 6 +- .../test/java/org/yb/pgsql/TestPgRegress.java | 5 + src/postgres/src/backend/commands/ybctype.c | 120 +- src/postgres/src/backend/executor/ybcExpr.c | 105 +- .../src/backend/postmaster/postmaster.c | 6 + src/postgres/src/include/pg_yb_utils.h | 1 - .../test/regress/expected/yb_timestamp.out | 1534 +++++++++++++++++ .../src/test/regress/sql/timestamp.sql | 45 +- .../src/test/regress/sql/yb_timestamp.sql | 192 +++ .../src/test/regress/yb_serial_schedule | 2 +- src/yb/docdb/CMakeLists.txt | 10 + src/yb/tools/CMakeLists.txt | 3 + src/yb/util/bfpg/CMakeLists.txt | 5 + src/yb/util/status.h | 9 +- 25 files changed, 2238 insertions(+), 194 deletions(-) create mode 100644 java/yb-client/src/test/java/org/yb/util/SideBySideDiff.java create mode 100644 src/postgres/src/test/regress/expected/yb_timestamp.out create mode 100644 src/postgres/src/test/regress/sql/yb_timestamp.sql diff --git a/build-support/compiler-wrappers/compiler-wrapper.sh b/build-support/compiler-wrappers/compiler-wrapper.sh index c04eed32886b..9c8dfd6b1a1d 100755 --- a/build-support/compiler-wrappers/compiler-wrapper.sh +++ b/build-support/compiler-wrappers/compiler-wrapper.sh @@ -30,6 +30,21 @@ readonly GENERATED_BUILD_DEBUG_SCRIPT_DIR=$HOME/.yb-build-debug-scripts readonly SCRIPT_NAME="compiler-wrapper.sh" declare -i -r MAX_INPUT_FILES_TO_SHOW=20 +# Files such as numeric.c, int.c, int8.c, and float.c get compiled with UBSAN (Undefined Behavior +# Sanitizer) turned off due to large number of overflow cases in them (by design). + +# numeric.c is compiled without UBSAN as a fix for a problem observed with Clang 5.0 and 6.0: +# undefined reference to `__muloti4' +# (full log at http://bit.ly/2lYdYnp). +# Related to the problem reported at http://bit.ly/2NvS6MR. + +# int.c and int8.c have a lot of assumptions regarding the exact resulting values of overflowing +# operations, and these assumptions are not true in UBSAN mode. + +# float.c compiled in UBSAN mode causes the following error on the yb_float4 test (server process +# crashes): http://bit.ly/2AW9oye + +readonly NO_UBSAN_RE='(numeric|int|int8|float)' # ------------------------------------------------------------------------------------------------- # Common functions @@ -453,14 +468,9 @@ local_build_exit_handler() { if [[ ${build_type:-} == "asan" && $PWD == */postgres_build/src/backend/utils/adt && - ( $compiler_args_str == *\ -c\ -o\ numeric.o\ numeric.c\ * || - $compiler_args_str == *\ -c\ -o\ int.o\ int.c\ * || - $compiler_args_str == *\ -c\ -o\ int8.o\ int8.c\ * ) ]]; then - # A hack for the problem observed in ASAN when compiling numeric.c with Clang 5.0 and 6.0. - # undefined reference to `__muloti4' - # (full log at http://bit.ly/2lYdYnp). - # Related to the problem reported at http://bit.ly/2NvS6MR. - + # Turn off UBSAN instrumentation in a number of PostgreSQL source files determined by the + # $NO_UBSAN_RE regular expression. See the definition of NO_UBSAN_RE for details. + $compiler_args_str =~ .*\ -c\ -o\ $NO_UBSAN_RE[.]o\ $NO_UBSAN_RE[.]c\ .* ]]; then rewritten_args=() for arg in "${compiler_args[@]}"; do case $arg in diff --git a/java/yb-client/src/test/java/org/yb/client/TestUtils.java b/java/yb-client/src/test/java/org/yb/client/TestUtils.java index bfa4c53b4cac..519f06845a73 100644 --- a/java/yb-client/src/test/java/org/yb/client/TestUtils.java +++ b/java/yb-client/src/test/java/org/yb/client/TestUtils.java @@ -466,4 +466,19 @@ public static void resetDefaultStdOutAndErr() { System.setErr(defaultStdErr); } + /** + * @param arr integer parameters + * @return the first of the given numbers that is positive + */ + public static int getFirstPositiveNumber(int... arr) { + for (int value : arr) { + if (value > 0) + return value; + } + if (arr.length > 0) { + return arr[arr.length - 1]; + } + throw new IllegalArgumentException("No numbers given to firstPositiveNumber"); + } + } diff --git a/java/yb-client/src/test/java/org/yb/minicluster/BaseMiniClusterTest.java b/java/yb-client/src/test/java/org/yb/minicluster/BaseMiniClusterTest.java index 7869ef5509ca..9e8fd335d9cf 100644 --- a/java/yb-client/src/test/java/org/yb/minicluster/BaseMiniClusterTest.java +++ b/java/yb-client/src/test/java/org/yb/minicluster/BaseMiniClusterTest.java @@ -33,17 +33,13 @@ public class BaseMiniClusterTest extends BaseYBTest { private static final Logger LOG = LoggerFactory.getLogger(BaseMiniClusterTest.class); - protected static final String NUM_MASTERS_PROP = "NUM_MASTERS"; + // TODO: review the usage of the constants below. + protected static final int NUM_MASTERS = 3; protected static final int NUM_TABLET_SERVERS = 3; - protected static final int DEFAULT_NUM_MASTERS = 3; + protected static final int STANDARD_DEVIATION_FACTOR = 2; protected static final int DEFAULT_TIMEOUT_MS = 50000; - // Number of masters that will be started for this test if we're starting - // a cluster. - protected static final int NUM_MASTERS = - Integer.getInteger(NUM_MASTERS_PROP, DEFAULT_NUM_MASTERS); - /** * This is used as the default timeout when calling YB Java client's async API. */ @@ -62,6 +58,18 @@ public class BaseMiniClusterTest extends BaseYBTest { protected static String masterAddresses; protected static List masterHostPorts; + protected int getReplicationFactor() { + return -1; + } + + protected int getInitialNumMasters() { + return -1; + } + + protected int getInitialNumTServers() { + return -1; + } + // Subclasses can override this to set the number of shards per tablet server. protected int overridableNumShardsPerTServer() { return MiniYBCluster.DEFAULT_NUM_SHARDS_PER_TSERVER; @@ -112,7 +120,13 @@ protected void createMiniCluster() throws Exception { if (!miniClusterEnabled()) { return; } - createMiniCluster(NUM_MASTERS, NUM_TABLET_SERVERS); + final int replicationFactor = getReplicationFactor(); + createMiniCluster( + TestUtils.getFirstPositiveNumber( + getInitialNumMasters(), replicationFactor, MiniYBCluster.DEFAULT_NUM_MASTERS), + TestUtils.getFirstPositiveNumber( + getInitialNumTServers(), replicationFactor, MiniYBCluster.DEFAULT_NUM_TSERVERS) + ); } /** @@ -141,6 +155,7 @@ public void createMiniCluster(int numMasters, List> tserverArgs) .tserverArgs(tserverArgs) .numShardsPerTServer(overridableNumShardsPerTServer()) .useIpWithCertificate(useIpWithCertificate) + .replicationFactor(getReplicationFactor()) .build(); masterAddresses = miniCluster.getMasterAddresses(); masterHostPorts = miniCluster.getMasterHostPorts(); diff --git a/java/yb-client/src/test/java/org/yb/minicluster/MiniYBCluster.java b/java/yb-client/src/test/java/org/yb/minicluster/MiniYBCluster.java index 2f8afb869432..4e2b584d2fd0 100644 --- a/java/yb-client/src/test/java/org/yb/minicluster/MiniYBCluster.java +++ b/java/yb-client/src/test/java/org/yb/minicluster/MiniYBCluster.java @@ -135,6 +135,7 @@ public class MiniYBCluster implements AutoCloseable { public static final int DEFAULT_NUM_SHARDS_PER_TSERVER = 3; + public static final int DEFAULT_NUM_MASTERS = 3; public static final int DEFAULT_NUM_TSERVERS = 3; private int numShardsPerTserver; @@ -150,6 +151,8 @@ public class MiniYBCluster implements AutoCloseable { private static final long DAEMON_MEMORY_LIMIT_HARD_BYTES_NON_TSAN = 1024 * 1024 * 1024; private static final long DAEMON_MEMORY_LIMIT_HARD_BYTES_TSAN = 512 * 1024 * 1024; + private int replicationFactor = -1; + /** * Not to be invoked directly, but through a {@link MiniYBClusterBuilder}. */ @@ -160,11 +163,13 @@ public class MiniYBCluster implements AutoCloseable { List> tserverArgs, int numShardsPerTserver, String testClassName, - boolean useIpWithCertificate) throws Exception { + boolean useIpWithCertificate, + int replicationFactor) throws Exception { this.defaultTimeoutMs = defaultTimeoutMs; this.testClassName = testClassName; this.numShardsPerTserver = numShardsPerTserver; this.useIpWithCertificate = useIpWithCertificate; + this.replicationFactor = replicationFactor; startCluster(numMasters, numTservers, masterArgs, tserverArgs); startSyncClient(); @@ -215,6 +220,10 @@ private List getCommonDaemonFlags() { commonFlags.add("--yb_num_shards_per_tserver=" + numShardsPerTserver); + if (replicationFactor > 0) { + commonFlags.add("--replication_factor=" + replicationFactor); + } + return commonFlags; } diff --git a/java/yb-client/src/test/java/org/yb/minicluster/MiniYBClusterBuilder.java b/java/yb-client/src/test/java/org/yb/minicluster/MiniYBClusterBuilder.java index 3da662bfb8e4..3709d628a564 100644 --- a/java/yb-client/src/test/java/org/yb/minicluster/MiniYBClusterBuilder.java +++ b/java/yb-client/src/test/java/org/yb/minicluster/MiniYBClusterBuilder.java @@ -26,6 +26,7 @@ public class MiniYBClusterBuilder { private List masterArgs = null; private List> tserverArgs = null; private String testClassName = null; + private int replicationFactor = -1; public MiniYBClusterBuilder numMasters(int numMasters) { this.numMasters = numMasters; @@ -85,8 +86,16 @@ public MiniYBClusterBuilder testClassName(String testClassName) { return this; } + /** + * Sets the replication factor for the mini-cluster. + */ + public MiniYBClusterBuilder replicationFactor(int replicationFactor) { + this.replicationFactor = replicationFactor; + return this; + } + public MiniYBCluster build() throws Exception { return new MiniYBCluster(numMasters, numTservers, defaultTimeoutMs, masterArgs, tserverArgs, - numShardsPerTServer, testClassName, useIpWithCertificate); + numShardsPerTServer, testClassName, useIpWithCertificate, replicationFactor); } } diff --git a/java/yb-client/src/test/java/org/yb/minicluster/MiniYBDaemon.java b/java/yb-client/src/test/java/org/yb/minicluster/MiniYBDaemon.java index fa8aed3fed17..fceabac96765 100644 --- a/java/yb-client/src/test/java/org/yb/minicluster/MiniYBDaemon.java +++ b/java/yb-client/src/test/java/org/yb/minicluster/MiniYBDaemon.java @@ -65,7 +65,7 @@ private void analyzeSystemLog() throws IOException { "tail -%d '%s' | egrep -i -C %d '%s'", NUM_LAST_SYSLOG_LINES_TO_USE, SYSLOG_PATH, SYSLOG_CONTEXT_NUM_LINES, regexStr)); cmdResult.logStderr(); - if (cmdResult.stdoutLines.isEmpty()) { + if (cmdResult.getStdoutLines().isEmpty()) { if (!terminatedNormally()) { LOG.warn("Could not find anything in " + SYSLOG_PATH + " relevant to the " + "disappearance of process: " + MiniYBDaemon.this); @@ -73,7 +73,7 @@ private void analyzeSystemLog() throws IOException { } else { LOG.warn("Potentially relevant lines from " + SYSLOG_PATH + " for termination of " + this + ":\n" + - StringUtil.joinLinesForLogging(cmdResult.stdoutLines)); + StringUtil.joinLinesForLogging(cmdResult.getStdoutLines())); } } @@ -89,7 +89,7 @@ private void analyzeMemoryUsage() throws IOException { int numMasters = 0; int numTservers = 0; List masterTserverPsLines = new ArrayList(); - for (String line : cmdResult.stdoutLines) { + for (String line : cmdResult.getStdoutLines()) { // Four parts: RSS, pid, executable path, arguments. String[] items = line.split("\\s+", 4); if (items.length < 4) { @@ -125,7 +125,7 @@ private void analyzeMemoryUsage() throws IOException { ", num tserver processes: " + numTservers + ", total tserver memory usage (MB): " + (totalTserverRssKB / 1024) + "; " + "ps output:\n" + - StringUtil.joinLinesForLogging(cmdResult.stdoutLines)); + StringUtil.joinLinesForLogging(cmdResult.getStdoutLines())); } else { LOG.info("Did not find any yb-master/yb-tserver processes in 'ps' output"); } diff --git a/java/yb-client/src/test/java/org/yb/util/CommandResult.java b/java/yb-client/src/test/java/org/yb/util/CommandResult.java index ccd2e5f7fa37..86ee72923134 100644 --- a/java/yb-client/src/test/java/org/yb/util/CommandResult.java +++ b/java/yb-client/src/test/java/org/yb/util/CommandResult.java @@ -20,10 +20,10 @@ public class CommandResult { private static final Logger LOG = LoggerFactory.getLogger(CommandResult.class); - public final String cmd; - public final int exitCode; - public final List stdoutLines; - public final List stderrLines; + private final String cmd; + private final int exitCode; + private final List stdoutLines; + private final List stderrLines; public CommandResult( String cmd, int exitCode, List stdoutLines, List stderrLines) { @@ -92,4 +92,9 @@ public List getStderrLines() { return stderrLines; } + @Override + public String toString() { + return "Result of running command {{ " + cmd + " }}: exit code " + exitCode; + } + } diff --git a/java/yb-client/src/test/java/org/yb/util/SanitizerUtil.java b/java/yb-client/src/test/java/org/yb/util/SanitizerUtil.java index fe2b632f3844..88be18db77dd 100644 --- a/java/yb-client/src/test/java/org/yb/util/SanitizerUtil.java +++ b/java/yb-client/src/test/java/org/yb/util/SanitizerUtil.java @@ -54,7 +54,11 @@ public static int nonTsanVsTsan(int nonTsanValue, int tsanValue) { /** @return a timeout multiplier to apply in tests based on the build type */ public static double getTimeoutMultiplier() { - return isTSAN() ? 3.0 : 1.0; + if (isTSAN()) + return 3; + if (isASAN()) + return 1.5; + return 1; } /** diff --git a/java/yb-client/src/test/java/org/yb/util/SideBySideDiff.java b/java/yb-client/src/test/java/org/yb/util/SideBySideDiff.java new file mode 100644 index 000000000000..2e19e0a6321a --- /dev/null +++ b/java/yb-client/src/test/java/org/yb/util/SideBySideDiff.java @@ -0,0 +1,228 @@ +// Copyright (c) YugaByte, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations +// under the License. +// +package org.yb.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +/** + * Produces a human-readable side-by-side diff between two files. + */ +public class SideBySideDiff { + + private static final Logger LOG = LoggerFactory.getLogger(SideBySideDiff.class); + + private File f1, f2; + + private List sxsDiffLines; + + /** + * Zero-based column of the middle of the side-by-side diff output as produced by the diff + * command. + */ + private int midColumn; + + private static Set VALID_MID_CHAR_SUPERSET = new TreeSet<>( + Arrays.asList(new Character[] {' ', '<', '>', '|'}) + ); + + private static Set VALID_LEFT_RIGHT_CHAR_SUPERSET = new TreeSet<>( + Arrays.asList(new Character[] {' '}) + ); + + /** + * charSetAtColumn[i] is the the set of characters in the diff at the 0-based column i. + * This is used to find the divider that is not always exactly in the middle of the width + * passed to the diff command. + */ + private List> charSetAtColumn = new ArrayList<>(); + + /** + * This width is given to the side-by-side diff call. Not necessarily the final displayed width. + */ + + public SideBySideDiff(File f1, File f2) { + this.f1 = f1; + this.f2 = f2; + } + + private Set getCharSetAtColumn(int i) { + while (i >= charSetAtColumn.size()) { + charSetAtColumn.add(null); + } + Set set = charSetAtColumn.get(i); + if (set != null) { + return set; + } + + set = new TreeSet<>(); + charSetAtColumn.set(i, set); + + for (String line : sxsDiffLines) { + if (i < line.length()) { + set.add(line.charAt(i)); + } + } + return set; + } + + private static List readLinesAndNormalize(File f) throws IOException { + return StringUtil.expandTabsAndRemoveTrailingSpaces(FileUtil.readLinesFrom(f)); + } + + private static void sanityCheckLinesMatch( + String fileDescription, List lines, int i, String lineFromDiff) { + if (i < 0 || i >= lines.size()) { + LOG.error("SideBySideDiff sanity check failed: trying to get line " + (i + 1) + " in the " + + fileDescription + " file (it has " + lines.size() + " lines)"); + return; + } + String lineFromFile = lines.get(i); + if (lineFromFile.equals(lineFromDiff)) { + LOG.error("SideBySideDiff sanity check failed: line " + (i + 1) + " from the " + + fileDescription + " file is\n" + lineFromFile + + "\nbut the diff tool implies it should be\n" + lineFromDiff); + } + } + + private static class SideBySideDiffLine { + int i1, i2; + String s1, s2; + char diffChar; + + public SideBySideDiffLine(int i1, String s1, int i2, String s2, char diffChar) { + this.i1 = i1; + this.s1 = s1; + this.i2 = i2; + this.s2 = s2; + this.diffChar = diffChar; + } + + String getLeftLineNumStr() { + if (diffChar != '>') { + return String.valueOf(i1 + 1); + } + return ""; + } + + String getRightLineNumStr() { + if (diffChar != '<') { + return String.valueOf(i2 + 1); + } + return ""; + } + } + + public String getSideBySideDiff() throws IOException { + StringBuilder result = new StringBuilder(); + List lines1 = readLinesAndNormalize(f1); + List lines2 = readLinesAndNormalize(f2); + + final int diffWidth = Math.max( + StringUtil.getMaxLineLength(lines1), + StringUtil.getMaxLineLength(lines2)) * 2 + 4; + + String diffCmd = String.format("diff -W%d -y --expand-tabs '%s' '%s'", diffWidth, f1, f2); + CommandResult commandResult = CommandUtil.runShellCommand(diffCmd); + List stdoutLines = commandResult.getStdoutLines(); + + sxsDiffLines = new ArrayList<>(); + + int maxSxsDiffLineLength = 0; + for (String line : stdoutLines) { + String expandedLine = StringUtil.expandTabs(line); + sxsDiffLines.add(expandedLine); + maxSxsDiffLineLength = Math.max(maxSxsDiffLineLength, expandedLine.length()); + } + + // This is not necessarily exactly where the mid-column is, but pretty close to it in practice. + final int midColumnGuess = diffWidth / 2 - 1; + + midColumn = -1; + + outerLoop: + for (int offsetFromMiddle = 0; offsetFromMiddle <= maxSxsDiffLineLength / 2; + ++offsetFromMiddle) { + for (int offsetDirection = -1; offsetDirection <= 1; offsetDirection += 2) { + int offset = midColumnGuess + offsetDirection * offsetFromMiddle; + if (offset >= 0 && offset < maxSxsDiffLineLength) { + Set leftSet = getCharSetAtColumn(offset - 1); + Set midSet = getCharSetAtColumn(offset); + Set rightSet = getCharSetAtColumn(offset + 1); + if (VALID_LEFT_RIGHT_CHAR_SUPERSET.containsAll(leftSet) && + VALID_LEFT_RIGHT_CHAR_SUPERSET.containsAll(rightSet) && + VALID_MID_CHAR_SUPERSET.containsAll(midSet)) { + midColumn = offset; + break outerLoop; + } + } + } + } + + if (midColumn == -1) { + LOG.error("Side-by-side diff raw output with tabs expanded:\n" + + StringUtil.expandTabsAndConcatenate(sxsDiffLines)); + throw new IOException( + "Was not able to find the mid-column of the side-by-side diff. " + + "See the raw output with tabs expanded in the log."); + } + + int i1 = 0; + int i2 = 0; + List outLines = new ArrayList<>(); + for (String diffLine : sxsDiffLines) { + String s1 = diffLine.substring(0, Math.min(midColumn - 1, diffLine.length())); + s1 = StringUtil.rtrim(s1); + + int offset2 = midColumn + 3; + String s2 = diffLine.length() > offset2 ? diffLine.substring(offset2) : ""; + s2 = StringUtil.rtrim(s2); + + char diffChar = midColumn < diffLine.length() ? diffLine.charAt(midColumn) : ' '; + + outLines.add(new SideBySideDiffLine(i1, s1, i2, s2, diffChar)); + if (diffChar != '<') { + // "<" would mean this line is unique to the left-hand-side file. + sanityCheckLinesMatch("rhs", lines2, i2, s2); + i2++; + } + if (diffChar != '>') { + // ">" would mean this line is unique to the right-hand-side file. + sanityCheckLinesMatch("lhs", lines1, i1, s1); + i1++; + } + } + + int valueWidth1 = 0; + for (SideBySideDiffLine sxsLine : outLines) { + valueWidth1 = Math.max(valueWidth1, sxsLine.s1.length()); + } + int lineNumWidth1 = String.valueOf(lines1.size()).length(); + int lineNumWidth2 = String.valueOf(lines2.size()).length(); + String fmt = "%" + lineNumWidth1 + "s " + + "%-" + valueWidth1 + "s %c %" + lineNumWidth2 + "s %s"; + for (SideBySideDiffLine sxsLine: outLines) { + result.append(StringUtil.rtrim( + String.format(fmt, sxsLine.getLeftLineNumStr(), sxsLine.s1, sxsLine.diffChar, + sxsLine.getRightLineNumStr(), sxsLine.s2))); + result.append('\n'); + } + + return result.toString(); + } + +} diff --git a/java/yb-client/src/test/java/org/yb/util/StringUtil.java b/java/yb-client/src/test/java/org/yb/util/StringUtil.java index b1b5382f782f..7bcd18646c39 100644 --- a/java/yb-client/src/test/java/org/yb/util/StringUtil.java +++ b/java/yb-client/src/test/java/org/yb/util/StringUtil.java @@ -12,10 +12,14 @@ // package org.yb.util; +import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; public final class StringUtil { + private final static Pattern RTRIM_RE = Pattern.compile("\\s+$"); + private StringUtil() { } @@ -73,4 +77,23 @@ public static String expandTabsAndConcatenate(List lines) { return sb.toString(); } + public static String rtrim(String s) { + return RTRIM_RE.matcher(s).replaceAll(""); + } + + public static List expandTabsAndRemoveTrailingSpaces(List lines) { + List result = new ArrayList<>(); + for (String line : lines) { + result.add(rtrim(expandTabs(line))); + } + return result; + } + + public static int getMaxLineLength(List lines) { + int maxLen = 0; + for (String line : lines) { + maxLen = Math.max(maxLen, line.length()); + } + return maxLen; + } } diff --git a/java/yb-cql/src/test/java/org/yb/cql/TestConsistencyLevels.java b/java/yb-cql/src/test/java/org/yb/cql/TestConsistencyLevels.java index ef1d4324f4e7..b87416c7e64e 100644 --- a/java/yb-cql/src/test/java/org/yb/cql/TestConsistencyLevels.java +++ b/java/yb-cql/src/test/java/org/yb/cql/TestConsistencyLevels.java @@ -14,35 +14,30 @@ package org.yb.cql; import com.datastax.driver.core.*; -import com.datastax.driver.core.exceptions.ProtocolError; import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; import com.datastax.driver.core.querybuilder.QueryBuilder; import com.google.common.net.HostAndPort; import com.yugabyte.driver.core.policies.PartitionAwarePolicy; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.yb.ColumnSchema; -import org.yb.Common; -import org.yb.Schema; -import org.yb.Type; +import org.yb.*; import org.yb.client.*; import org.yb.consensus.Metadata; import org.yb.minicluster.Metrics; import org.yb.minicluster.MiniYBCluster; import org.yb.minicluster.MiniYBDaemon; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import static junit.framework.TestCase.assertEquals; import static org.yb.AssertionWrappers.assertNotNull; import static org.yb.AssertionWrappers.assertTrue; -import static org.yb.AssertionWrappers.fail; - -import org.yb.YBTestRunner; - -import org.junit.runner.RunWith; @RunWith(value=YBTestRunner.class) public class TestConsistencyLevels extends BaseCQLTest { diff --git a/java/yb-pgsql/src/test/java/org/yb/pgsql/PgRegressRunner.java b/java/yb-pgsql/src/test/java/org/yb/pgsql/PgRegressRunner.java index ca6f0f0aa54a..846aacd3b205 100644 --- a/java/yb-pgsql/src/test/java/org/yb/pgsql/PgRegressRunner.java +++ b/java/yb-pgsql/src/test/java/org/yb/pgsql/PgRegressRunner.java @@ -159,10 +159,8 @@ public void stop() throws InterruptedException, IOException { LOG.warn("Actual test output file " + resultFile + " not found."); continue; } - String diffCmd = String.format("diff -W250 -y '%s' '%s'", expectedFile, resultFile); - CommandResult diffResult = CommandUtil.runShellCommand(diffCmd); - LOG.warn("Output from: " + diffCmd + "\n" + - StringUtil.expandTabsAndConcatenate(diffResult.getStdoutLines())); + LOG.warn("Side-by-side diff between expected output and actual output:\n" + + new SideBySideDiff(expectedFile, resultFile).getSideBySideDiff()); } } diff --git a/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegress.java b/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegress.java index edf72df5ec88..3b88a2e5dbf9 100644 --- a/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegress.java +++ b/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgRegress.java @@ -30,4 +30,9 @@ public void testPgRegress() throws Exception { pgRegress.stop(); } + @Override + protected int getReplicationFactor() { + return 1; + } + } diff --git a/src/postgres/src/backend/commands/ybctype.c b/src/postgres/src/backend/commands/ybctype.c index d19100f60d5f..1dd8e6e96aa6 100644 --- a/src/postgres/src/backend/commands/ybctype.c +++ b/src/postgres/src/backend/commands/ybctype.c @@ -93,82 +93,72 @@ YBCDataTypeFromName(TypeName *typeName) return YB_YQL_DATA_TYPE_STRING; } +#define REPORT_INVALID_TYPE_AND_BREAK() \ + YB_REPORT_TYPE_NOT_SUPPORTED(type_id); break + switch (type_id) { - case BOOLOID: - return YB_YQL_DATA_TYPE_BOOL; - case CHAROID: - case NAMEOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; - case INT8OID: - return YB_YQL_DATA_TYPE_INT64; - case INT2OID: - return YB_YQL_DATA_TYPE_INT16; - case INT4OID: - return YB_YQL_DATA_TYPE_INT32; - case REGPROCOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; + case BOOLOID: return YB_YQL_DATA_TYPE_BOOL; + case INT2OID: return YB_YQL_DATA_TYPE_INT16; + case INT4OID: return YB_YQL_DATA_TYPE_INT32; + case INT8OID: return YB_YQL_DATA_TYPE_INT64; + case FLOAT4OID: return YB_YQL_DATA_TYPE_FLOAT; + case FLOAT8OID: return YB_YQL_DATA_TYPE_DOUBLE; case OIDOID: /* TODO: need to use UINT32 here */ return YB_YQL_DATA_TYPE_INT32; - case TIDOID: - case XIDOID: - case CIDOID: - case POINTOID: - case LSEGOID: - case PATHOID: - case BOXOID: - case POLYGONOID: - case LINEOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; - case FLOAT4OID: - return YB_YQL_DATA_TYPE_FLOAT; - case FLOAT8OID: - return YB_YQL_DATA_TYPE_DOUBLE; - case ABSTIMEOID: - case RELTIMEOID: - case TINTERVALOID: - case UNKNOWNOID: - case CIRCLEOID: - case CASHOID: - case INETOID: - case CIDROID: - case DATEOID: - case TIMEOID: case TIMESTAMPOID: case TIMESTAMPTZOID: - case INTERVALOID: - case TIMETZOID: - case VARBITOID: - case NUMERICOID: - case REFCURSOROID: - case REGPROCEDUREOID: - case REGOPEROID: - case REGOPERATOROID: - case REGCLASSOID: - case REGTYPEOID: - case REGROLEOID: - case REGNAMESPACEOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; - case UUIDOID: - case LSNOID: - case TSVECTOROID: - case GTSVECTOROID: - case TSQUERYOID: - case REGCONFIGOID: - case REGDICTIONARYOID: - case INT4RANGEOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); + /** TODO: should probably be UINT64 */ + return YB_YQL_DATA_TYPE_INT64; case INT4ARRAYOID: /** TODO: make this binary */ return YB_YQL_DATA_TYPE_STRING; - default: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); + case REGPROCOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CHAROID: REPORT_INVALID_TYPE_AND_BREAK(); + case NAMEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TIDOID: REPORT_INVALID_TYPE_AND_BREAK(); + case XIDOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CIDOID: REPORT_INVALID_TYPE_AND_BREAK(); + case POINTOID: REPORT_INVALID_TYPE_AND_BREAK(); + case LSEGOID: REPORT_INVALID_TYPE_AND_BREAK(); + case PATHOID: REPORT_INVALID_TYPE_AND_BREAK(); + case BOXOID: REPORT_INVALID_TYPE_AND_BREAK(); + case POLYGONOID: REPORT_INVALID_TYPE_AND_BREAK(); + case LINEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case ABSTIMEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case RELTIMEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TINTERVALOID: REPORT_INVALID_TYPE_AND_BREAK(); + case UNKNOWNOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CIRCLEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CASHOID: REPORT_INVALID_TYPE_AND_BREAK(); + case INETOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CIDROID: REPORT_INVALID_TYPE_AND_BREAK(); + case DATEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TIMEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case INTERVALOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TIMETZOID: REPORT_INVALID_TYPE_AND_BREAK(); + case VARBITOID: REPORT_INVALID_TYPE_AND_BREAK(); + case NUMERICOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REFCURSOROID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGPROCEDUREOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGOPEROID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGOPERATOROID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGCLASSOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGTYPEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGROLEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGNAMESPACEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case UUIDOID: REPORT_INVALID_TYPE_AND_BREAK(); + case LSNOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TSVECTOROID: REPORT_INVALID_TYPE_AND_BREAK(); + case GTSVECTOROID: REPORT_INVALID_TYPE_AND_BREAK(); + case TSQUERYOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGCONFIGOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGDICTIONARYOID: REPORT_INVALID_TYPE_AND_BREAK(); + case INT4RANGEOID: REPORT_INVALID_TYPE_AND_BREAK(); + default: REPORT_INVALID_TYPE_AND_BREAK(); } +#undef REPORT_INVALID_TYPE_AND_BREAK return -1; } diff --git a/src/postgres/src/backend/executor/ybcExpr.c b/src/postgres/src/backend/executor/ybcExpr.c index a8084984a5a7..9a19f6b44053 100644 --- a/src/postgres/src/backend/executor/ybcExpr.c +++ b/src/postgres/src/backend/executor/ybcExpr.c @@ -64,15 +64,14 @@ YBCPgExpr YBCNewConstant(YBCPgStatement ybc_stmt, Oid type_id, Datum datum, bool return YBCNewBinaryConstant(ybc_stmt, type_id, datum, is_null); } +#define REPORT_INVALID_TYPE_AND_BREAK() \ + YB_REPORT_TYPE_NOT_SUPPORTED(type_id); break + switch (type_id) { case BOOLOID: HandleYBStatus(YBCPgNewConstantBool(ybc_stmt, DatumGetInt64(datum), is_null, &expr)); break; - case CHAROID: - case NAMEOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; case INT8OID: HandleYBStatus(YBCPgNewConstantInt8(ybc_stmt, DatumGetInt64(datum), is_null, &expr)); break; @@ -82,73 +81,67 @@ YBCPgExpr YBCNewConstant(YBCPgStatement ybc_stmt, Oid type_id, Datum datum, bool case INT4OID: HandleYBStatus(YBCPgNewConstantInt4(ybc_stmt, DatumGetInt32(datum), is_null, &expr)); break; - case REGPROCOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; case OIDOID: HandleYBStatus(YBCPgNewConstantInt4(ybc_stmt, DatumGetInt32(datum), is_null, &expr)); break; - case TIDOID: - case XIDOID: - case CIDOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; - case POINTOID: - case LSEGOID: - case PATHOID: - case BOXOID: - case POLYGONOID: - case LINEOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; case FLOAT4OID: HandleYBStatus(YBCPgNewConstantFloat4(ybc_stmt, DatumGetFloat4(datum), is_null, &expr)); break; case FLOAT8OID: HandleYBStatus(YBCPgNewConstantFloat8(ybc_stmt, DatumGetFloat8(datum), is_null, &expr)); break; - case ABSTIMEOID: - case RELTIMEOID: - case TINTERVALOID: - case UNKNOWNOID: - case CIRCLEOID: - case CASHOID: - case INETOID: - case CIDROID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - break; - case DATEOID: - case TIMEOID: case TIMESTAMPOID: case TIMESTAMPTZOID: - case INTERVALOID: - case TIMETZOID: - case VARBITOID: - case NUMERICOID: - case REFCURSOROID: - case REGPROCEDUREOID: - case REGOPEROID: - case REGOPERATOROID: - case REGCLASSOID: - case REGTYPEOID: - case REGROLEOID: - case REGNAMESPACEOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); - case UUIDOID: - case LSNOID: - case TSVECTOROID: - case GTSVECTOROID: - case TSQUERYOID: - case REGCONFIGOID: - case REGDICTIONARYOID: - case INT4RANGEOID: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); + HandleYBStatus(YBCPgNewConstantInt8(ybc_stmt, DatumGetInt64(datum), is_null, &expr)); + break; case INT4ARRAYOID: expr = YBCNewBinaryConstant(ybc_stmt, type_id, datum, is_null); break; - default: - YB_REPORT_TYPE_NOT_SUPPORTED(type_id); + case REGPROCOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CHAROID: REPORT_INVALID_TYPE_AND_BREAK(); + case NAMEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TIDOID: REPORT_INVALID_TYPE_AND_BREAK(); + case XIDOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CIDOID: REPORT_INVALID_TYPE_AND_BREAK(); + case POINTOID: REPORT_INVALID_TYPE_AND_BREAK(); + case LSEGOID: REPORT_INVALID_TYPE_AND_BREAK(); + case PATHOID: REPORT_INVALID_TYPE_AND_BREAK(); + case BOXOID: REPORT_INVALID_TYPE_AND_BREAK(); + case POLYGONOID: REPORT_INVALID_TYPE_AND_BREAK(); + case LINEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case ABSTIMEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case RELTIMEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TINTERVALOID: REPORT_INVALID_TYPE_AND_BREAK(); + case UNKNOWNOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CIRCLEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CASHOID: REPORT_INVALID_TYPE_AND_BREAK(); + case INETOID: REPORT_INVALID_TYPE_AND_BREAK(); + case CIDROID: REPORT_INVALID_TYPE_AND_BREAK(); + case DATEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TIMEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case INTERVALOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TIMETZOID: REPORT_INVALID_TYPE_AND_BREAK(); + case VARBITOID: REPORT_INVALID_TYPE_AND_BREAK(); + case NUMERICOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REFCURSOROID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGPROCEDUREOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGOPEROID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGOPERATOROID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGCLASSOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGTYPEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGROLEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGNAMESPACEOID: REPORT_INVALID_TYPE_AND_BREAK(); + case UUIDOID: REPORT_INVALID_TYPE_AND_BREAK(); + case LSNOID: REPORT_INVALID_TYPE_AND_BREAK(); + case TSVECTOROID: REPORT_INVALID_TYPE_AND_BREAK(); + case GTSVECTOROID: REPORT_INVALID_TYPE_AND_BREAK(); + case TSQUERYOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGCONFIGOID: REPORT_INVALID_TYPE_AND_BREAK(); + case REGDICTIONARYOID: REPORT_INVALID_TYPE_AND_BREAK(); + case INT4RANGEOID: REPORT_INVALID_TYPE_AND_BREAK(); + default: REPORT_INVALID_TYPE_AND_BREAK(); } +#undef REPORT_INVALID_TYPE_AND_BREAK if (expr == NULL) { YBC_LOG_FATAL("Trying to return NULL from %s", __PRETTY_FUNCTION__); diff --git a/src/postgres/src/backend/postmaster/postmaster.c b/src/postgres/src/backend/postmaster/postmaster.c index 66fc3a83a7a5..948b09bc9255 100644 --- a/src/postgres/src/backend/postmaster/postmaster.c +++ b/src/postgres/src/backend/postmaster/postmaster.c @@ -4362,7 +4362,13 @@ BackendRun(Port *port) #endif /* slightly hacky way to convert timestamptz into integers */ TimestampDifference(0, port->SessionStartTime, &secs, &usecs); +#ifdef ADDRESS_SANITIZER + /* YugaByte fix for ASAN */ + srandom((unsigned int) (MyProcPid ^ ((int64_t) usecs << 12) ^ secs)); +#else srandom((unsigned int) (MyProcPid ^ (usecs << 12) ^ secs)); +#endif + /* * Now, build the argv vector that will be given to PostgresMain. diff --git a/src/postgres/src/include/pg_yb_utils.h b/src/postgres/src/include/pg_yb_utils.h index a2fd008bfd1f..c77d7d5e9bbe 100644 --- a/src/postgres/src/include/pg_yb_utils.h +++ b/src/postgres/src/include/pg_yb_utils.h @@ -142,7 +142,6 @@ bool YBIsEnabledInPostgresEnvVar(); computed_type_id, YBPgTypeOidToStr(computed_type_id)))); \ } while (0) - /** * Determines if PostgreSQL should restart all child processes if one of them * crashes. This behavior usually shows up in the log like so: diff --git a/src/postgres/src/test/regress/expected/yb_timestamp.out b/src/postgres/src/test/regress/expected/yb_timestamp.out new file mode 100644 index 000000000000..791d3fdeee11 --- /dev/null +++ b/src/postgres/src/test/regress/expected/yb_timestamp.out @@ -0,0 +1,1534 @@ +-- +-- TIMESTAMP +-- +CREATE TABLE TIMESTAMP_TBL (i int PRIMARY KEY, d1 timestamp(2) without time zone); +-- Special values +INSERT INTO TIMESTAMP_TBL VALUES (10, '-infinity'); +INSERT INTO TIMESTAMP_TBL VALUES (20, 'infinity'); +INSERT INTO TIMESTAMP_TBL VALUES (30, 'epoch'); +-- Obsolete special values +INSERT INTO TIMESTAMP_TBL VALUES (40, 'invalid'); +ERROR: date/time value "invalid" is no longer supported +LINE 1: INSERT INTO TIMESTAMP_TBL VALUES (40, 'invalid'); + ^ +INSERT INTO TIMESTAMP_TBL VALUES (50, 'undefined'); +ERROR: date/time value "undefined" is no longer supported +LINE 1: INSERT INTO TIMESTAMP_TBL VALUES (50, 'undefined'); + ^ +INSERT INTO TIMESTAMP_TBL VALUES (60, 'current'); +ERROR: date/time value "current" is no longer supported +LINE 1: INSERT INTO TIMESTAMP_TBL VALUES (60, 'current'); + ^ +-- Postgres v6.0 standard output format +INSERT INTO TIMESTAMP_TBL VALUES (70, 'Mon Feb 10 17:32:01 1997 PST'); +-- Variations on Postgres v6.1 standard output format +INSERT INTO TIMESTAMP_TBL VALUES (75, 'Mon Feb 10 17:32:01.000001 1997 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (80, 'Mon Feb 10 17:32:01.999999 1997 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (90, 'Mon Feb 10 17:32:01.4 1997 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (100, 'Mon Feb 10 17:32:01.5 1997 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (110, 'Mon Feb 10 17:32:01.6 1997 PST'); +-- ISO 8601 format +INSERT INTO TIMESTAMP_TBL VALUES (120, '1997-01-02'); +INSERT INTO TIMESTAMP_TBL VALUES (130, '1997-01-02 03:04:05'); +INSERT INTO TIMESTAMP_TBL VALUES (140, '1997-02-10 17:32:01-08'); +INSERT INTO TIMESTAMP_TBL VALUES (150, '1997-02-10 17:32:01-0800'); +INSERT INTO TIMESTAMP_TBL VALUES (160, '1997-02-10 17:32:01 -08:00'); +INSERT INTO TIMESTAMP_TBL VALUES (170, '19970210 173201 -0800'); +INSERT INTO TIMESTAMP_TBL VALUES (180, '1997-06-10 17:32:01 -07:00'); +INSERT INTO TIMESTAMP_TBL VALUES (190, '2001-09-22T18:19:20'); +-- POSIX format (note that the timezone abbrev is just decoration here) +INSERT INTO TIMESTAMP_TBL VALUES (200, '2000-03-15 08:14:01 GMT+8'); +INSERT INTO TIMESTAMP_TBL VALUES (210, '2000-03-15 13:14:02 GMT-1'); +INSERT INTO TIMESTAMP_TBL VALUES (220, '2000-03-15 12:14:03 GMT-2'); +INSERT INTO TIMESTAMP_TBL VALUES (230, '2000-03-15 03:14:04 PST+8'); +INSERT INTO TIMESTAMP_TBL VALUES (240, '2000-03-15 02:14:05 MST+7:00'); +-- Variations for acceptable input formats +INSERT INTO TIMESTAMP_TBL VALUES (250, 'Feb 10 17:32:01 1997 -0800'); +INSERT INTO TIMESTAMP_TBL VALUES (260, 'Feb 10 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (270, 'Feb 10 5:32PM 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (280, '1997/02/10 17:32:01-0800'); +INSERT INTO TIMESTAMP_TBL VALUES (290, '1997-02-10 17:32:01 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (300, 'Feb-10-1997 17:32:01 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (310, '02-10-1997 17:32:01 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (320, '19970210 173201 PST'); +set datestyle to ymd; +INSERT INTO TIMESTAMP_TBL VALUES (330, '97FEB10 5:32:01PM UTC'); +INSERT INTO TIMESTAMP_TBL VALUES (340, '97/02/10 17:32:01 UTC'); +reset datestyle; +INSERT INTO TIMESTAMP_TBL VALUES (350, '1997.041 17:32:01 UTC'); +INSERT INTO TIMESTAMP_TBL VALUES (360, '19970210 173201 America/New_York'); +-- this fails (even though TZ is a no-op, we still look it up) +INSERT INTO TIMESTAMP_TBL VALUES (370, '19970710 173201 America/Does_not_exist'); +ERROR: time zone "america/does_not_exist" not recognized +LINE 1: INSERT INTO TIMESTAMP_TBL VALUES (370, '19970710 173201 Amer... + ^ +-- Check date conversion and date arithmetic +INSERT INTO TIMESTAMP_TBL VALUES (380, '1997-06-10 18:32:01 PDT'); +INSERT INTO TIMESTAMP_TBL VALUES (390, 'Feb 10 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (400, 'Feb 11 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (410, 'Feb 12 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (420, 'Feb 13 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (430, 'Feb 14 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (440, 'Feb 15 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (450, 'Feb 16 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (460, 'Feb 16 17:32:01 0097 BC'); +INSERT INTO TIMESTAMP_TBL VALUES (470, 'Feb 16 17:32:01 0097'); +INSERT INTO TIMESTAMP_TBL VALUES (480, 'Feb 16 17:32:01 0597'); +INSERT INTO TIMESTAMP_TBL VALUES (490, 'Feb 16 17:32:01 1097'); +INSERT INTO TIMESTAMP_TBL VALUES (500, 'Feb 16 17:32:01 1697'); +INSERT INTO TIMESTAMP_TBL VALUES (510, 'Feb 16 17:32:01 1797'); +INSERT INTO TIMESTAMP_TBL VALUES (520, 'Feb 16 17:32:01 1897'); +INSERT INTO TIMESTAMP_TBL VALUES (530, 'Feb 16 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (540, 'Feb 16 17:32:01 2097'); +INSERT INTO TIMESTAMP_TBL VALUES (550, 'Feb 28 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (560, 'Feb 29 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (570, 'Mar 01 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (580, 'Dec 30 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (590, 'Dec 31 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (600, 'Jan 01 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (610, 'Feb 28 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (620, 'Feb 29 17:32:01 1997'); +ERROR: date/time field value out of range: "Feb 29 17:32:01 1997" +LINE 1: INSERT INTO TIMESTAMP_TBL VALUES (620, 'Feb 29 17:32:01 1997... + ^ +INSERT INTO TIMESTAMP_TBL VALUES (630, 'Mar 01 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (640, 'Dec 30 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (650, 'Dec 31 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (660, 'Dec 31 17:32:01 1999'); +INSERT INTO TIMESTAMP_TBL VALUES (670, 'Jan 01 17:32:01 2000'); +INSERT INTO TIMESTAMP_TBL VALUES (680, 'Dec 31 17:32:01 2000'); +INSERT INTO TIMESTAMP_TBL VALUES (690, 'Jan 01 17:32:01 2001'); +-- Currently unsupported syntax and ranges +INSERT INTO TIMESTAMP_TBL VALUES (700, 'Feb 16 17:32:01 -0097'); +ERROR: time zone displacement out of range: "Feb 16 17:32:01 -0097" +LINE 1: INSERT INTO TIMESTAMP_TBL VALUES (700, 'Feb 16 17:32:01 -009... + ^ +INSERT INTO TIMESTAMP_TBL VALUES (710, 'Feb 16 17:32:01 5097 BC'); +ERROR: timestamp out of range: "Feb 16 17:32:01 5097 BC" +LINE 1: INSERT INTO TIMESTAMP_TBL VALUES (710, 'Feb 16 17:32:01 5097... + ^ +SELECT '' AS "64", d1 FROM TIMESTAMP_TBL ORDER BY i; + 64 | d1 +----+----------------------------- + | -infinity + | infinity + | Thu Jan 01 00:00:00 1970 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:02 1997 + | Mon Feb 10 17:32:01.4 1997 + | Mon Feb 10 17:32:01.5 1997 + | Mon Feb 10 17:32:01.6 1997 + | Thu Jan 02 00:00:00 1997 + | Thu Jan 02 03:04:05 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Jun 10 17:32:01 1997 + | Sat Sep 22 18:19:20 2001 + | Wed Mar 15 08:14:01 2000 + | Wed Mar 15 13:14:02 2000 + | Wed Mar 15 12:14:03 2000 + | Wed Mar 15 03:14:04 2000 + | Wed Mar 15 02:14:05 2000 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:00 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Jun 10 18:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Feb 11 17:32:01 1997 + | Wed Feb 12 17:32:01 1997 + | Thu Feb 13 17:32:01 1997 + | Fri Feb 14 17:32:01 1997 + | Sat Feb 15 17:32:01 1997 + | Sun Feb 16 17:32:01 1997 + | Tue Feb 16 17:32:01 0097 BC + | Sat Feb 16 17:32:01 0097 + | Thu Feb 16 17:32:01 0597 + | Tue Feb 16 17:32:01 1097 + | Sat Feb 16 17:32:01 1697 + | Thu Feb 16 17:32:01 1797 + | Tue Feb 16 17:32:01 1897 + | Sun Feb 16 17:32:01 1997 + | Sat Feb 16 17:32:01 2097 + | Wed Feb 28 17:32:01 1996 + | Thu Feb 29 17:32:01 1996 + | Fri Mar 01 17:32:01 1996 + | Mon Dec 30 17:32:01 1996 + | Tue Dec 31 17:32:01 1996 + | Wed Jan 01 17:32:01 1997 + | Fri Feb 28 17:32:01 1997 + | Sat Mar 01 17:32:01 1997 + | Tue Dec 30 17:32:01 1997 + | Wed Dec 31 17:32:01 1997 + | Fri Dec 31 17:32:01 1999 + | Sat Jan 01 17:32:01 2000 + | Sun Dec 31 17:32:01 2000 + | Mon Jan 01 17:32:01 2001 +(65 rows) + +-- Check behavior at the lower boundary of the timestamp range +SELECT '4714-11-24 00:00:00 BC'::timestamp; + timestamp +----------------------------- + Mon Nov 24 00:00:00 4714 BC +(1 row) + +SELECT '4714-11-23 23:59:59 BC'::timestamp; -- out of range +ERROR: timestamp out of range: "4714-11-23 23:59:59 BC" +LINE 1: SELECT '4714-11-23 23:59:59 BC'::timestamp; + ^ +-- The upper boundary differs between integer and float timestamps, so no check +-- Demonstrate functions and operators +SELECT '' AS "48", d1 FROM TIMESTAMP_TBL + WHERE d1 > timestamp without time zone '1997-01-02' ORDER BY i; + 48 | d1 +----+---------------------------- + | infinity + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:02 1997 + | Mon Feb 10 17:32:01.4 1997 + | Mon Feb 10 17:32:01.5 1997 + | Mon Feb 10 17:32:01.6 1997 + | Thu Jan 02 03:04:05 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Jun 10 17:32:01 1997 + | Sat Sep 22 18:19:20 2001 + | Wed Mar 15 08:14:01 2000 + | Wed Mar 15 13:14:02 2000 + | Wed Mar 15 12:14:03 2000 + | Wed Mar 15 03:14:04 2000 + | Wed Mar 15 02:14:05 2000 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:00 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Jun 10 18:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Feb 11 17:32:01 1997 + | Wed Feb 12 17:32:01 1997 + | Thu Feb 13 17:32:01 1997 + | Fri Feb 14 17:32:01 1997 + | Sat Feb 15 17:32:01 1997 + | Sun Feb 16 17:32:01 1997 + | Sun Feb 16 17:32:01 1997 + | Sat Feb 16 17:32:01 2097 + | Fri Feb 28 17:32:01 1997 + | Sat Mar 01 17:32:01 1997 + | Tue Dec 30 17:32:01 1997 + | Wed Dec 31 17:32:01 1997 + | Fri Dec 31 17:32:01 1999 + | Sat Jan 01 17:32:01 2000 + | Sun Dec 31 17:32:01 2000 + | Mon Jan 01 17:32:01 2001 +(49 rows) + +SELECT '' AS "15", d1 FROM TIMESTAMP_TBL + WHERE d1 < timestamp without time zone '1997-01-02' ORDER BY i; + 15 | d1 +----+----------------------------- + | -infinity + | Thu Jan 01 00:00:00 1970 + | Tue Feb 16 17:32:01 0097 BC + | Sat Feb 16 17:32:01 0097 + | Thu Feb 16 17:32:01 0597 + | Tue Feb 16 17:32:01 1097 + | Sat Feb 16 17:32:01 1697 + | Thu Feb 16 17:32:01 1797 + | Tue Feb 16 17:32:01 1897 + | Wed Feb 28 17:32:01 1996 + | Thu Feb 29 17:32:01 1996 + | Fri Mar 01 17:32:01 1996 + | Mon Dec 30 17:32:01 1996 + | Tue Dec 31 17:32:01 1996 + | Wed Jan 01 17:32:01 1997 +(15 rows) + +SELECT '' AS one, d1 FROM TIMESTAMP_TBL + WHERE d1 = timestamp without time zone '1997-01-02' ORDER BY i; + one | d1 +-----+-------------------------- + | Thu Jan 02 00:00:00 1997 +(1 row) + +SELECT '' AS "63", d1 FROM TIMESTAMP_TBL + WHERE d1 != timestamp without time zone '1997-01-02' ORDER BY i; + 63 | d1 +----+----------------------------- + | -infinity + | infinity + | Thu Jan 01 00:00:00 1970 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:02 1997 + | Mon Feb 10 17:32:01.4 1997 + | Mon Feb 10 17:32:01.5 1997 + | Mon Feb 10 17:32:01.6 1997 + | Thu Jan 02 03:04:05 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Jun 10 17:32:01 1997 + | Sat Sep 22 18:19:20 2001 + | Wed Mar 15 08:14:01 2000 + | Wed Mar 15 13:14:02 2000 + | Wed Mar 15 12:14:03 2000 + | Wed Mar 15 03:14:04 2000 + | Wed Mar 15 02:14:05 2000 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:00 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Jun 10 18:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Feb 11 17:32:01 1997 + | Wed Feb 12 17:32:01 1997 + | Thu Feb 13 17:32:01 1997 + | Fri Feb 14 17:32:01 1997 + | Sat Feb 15 17:32:01 1997 + | Sun Feb 16 17:32:01 1997 + | Tue Feb 16 17:32:01 0097 BC + | Sat Feb 16 17:32:01 0097 + | Thu Feb 16 17:32:01 0597 + | Tue Feb 16 17:32:01 1097 + | Sat Feb 16 17:32:01 1697 + | Thu Feb 16 17:32:01 1797 + | Tue Feb 16 17:32:01 1897 + | Sun Feb 16 17:32:01 1997 + | Sat Feb 16 17:32:01 2097 + | Wed Feb 28 17:32:01 1996 + | Thu Feb 29 17:32:01 1996 + | Fri Mar 01 17:32:01 1996 + | Mon Dec 30 17:32:01 1996 + | Tue Dec 31 17:32:01 1996 + | Wed Jan 01 17:32:01 1997 + | Fri Feb 28 17:32:01 1997 + | Sat Mar 01 17:32:01 1997 + | Tue Dec 30 17:32:01 1997 + | Wed Dec 31 17:32:01 1997 + | Fri Dec 31 17:32:01 1999 + | Sat Jan 01 17:32:01 2000 + | Sun Dec 31 17:32:01 2000 + | Mon Jan 01 17:32:01 2001 +(64 rows) + +SELECT '' AS "16", d1 FROM TIMESTAMP_TBL + WHERE d1 <= timestamp without time zone '1997-01-02' ORDER BY i; + 16 | d1 +----+----------------------------- + | -infinity + | Thu Jan 01 00:00:00 1970 + | Thu Jan 02 00:00:00 1997 + | Tue Feb 16 17:32:01 0097 BC + | Sat Feb 16 17:32:01 0097 + | Thu Feb 16 17:32:01 0597 + | Tue Feb 16 17:32:01 1097 + | Sat Feb 16 17:32:01 1697 + | Thu Feb 16 17:32:01 1797 + | Tue Feb 16 17:32:01 1897 + | Wed Feb 28 17:32:01 1996 + | Thu Feb 29 17:32:01 1996 + | Fri Mar 01 17:32:01 1996 + | Mon Dec 30 17:32:01 1996 + | Tue Dec 31 17:32:01 1996 + | Wed Jan 01 17:32:01 1997 +(16 rows) + +SELECT '' AS "49", d1 FROM TIMESTAMP_TBL + WHERE d1 >= timestamp without time zone '1997-01-02' ORDER BY i; + 49 | d1 +----+---------------------------- + | infinity + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:02 1997 + | Mon Feb 10 17:32:01.4 1997 + | Mon Feb 10 17:32:01.5 1997 + | Mon Feb 10 17:32:01.6 1997 + | Thu Jan 02 00:00:00 1997 + | Thu Jan 02 03:04:05 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Jun 10 17:32:01 1997 + | Sat Sep 22 18:19:20 2001 + | Wed Mar 15 08:14:01 2000 + | Wed Mar 15 13:14:02 2000 + | Wed Mar 15 12:14:03 2000 + | Wed Mar 15 03:14:04 2000 + | Wed Mar 15 02:14:05 2000 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:00 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Jun 10 18:32:01 1997 + | Mon Feb 10 17:32:01 1997 + | Tue Feb 11 17:32:01 1997 + | Wed Feb 12 17:32:01 1997 + | Thu Feb 13 17:32:01 1997 + | Fri Feb 14 17:32:01 1997 + | Sat Feb 15 17:32:01 1997 + | Sun Feb 16 17:32:01 1997 + | Sun Feb 16 17:32:01 1997 + | Sat Feb 16 17:32:01 2097 + | Fri Feb 28 17:32:01 1997 + | Sat Mar 01 17:32:01 1997 + | Tue Dec 30 17:32:01 1997 + | Wed Dec 31 17:32:01 1997 + | Fri Dec 31 17:32:01 1999 + | Sat Jan 01 17:32:01 2000 + | Sun Dec 31 17:32:01 2000 + | Mon Jan 01 17:32:01 2001 +(50 rows) + +SELECT '' AS "54", d1 - timestamp without time zone '1997-01-02' AS diff + FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01' ORDER BY i; + 54 | diff +----+---------------------------------------- + | @ 9863 days ago + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 2 secs + | @ 39 days 17 hours 32 mins 1.4 secs + | @ 39 days 17 hours 32 mins 1.5 secs + | @ 39 days 17 hours 32 mins 1.6 secs + | @ 0 + | @ 3 hours 4 mins 5 secs + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 159 days 17 hours 32 mins 1 sec + | @ 1724 days 18 hours 19 mins 20 secs + | @ 1168 days 8 hours 14 mins 1 sec + | @ 1168 days 13 hours 14 mins 2 secs + | @ 1168 days 12 hours 14 mins 3 secs + | @ 1168 days 3 hours 14 mins 4 secs + | @ 1168 days 2 hours 14 mins 5 secs + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 159 days 18 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 40 days 17 hours 32 mins 1 sec + | @ 41 days 17 hours 32 mins 1 sec + | @ 42 days 17 hours 32 mins 1 sec + | @ 43 days 17 hours 32 mins 1 sec + | @ 44 days 17 hours 32 mins 1 sec + | @ 45 days 17 hours 32 mins 1 sec + | @ 45 days 17 hours 32 mins 1 sec + | @ 308 days 6 hours 27 mins 59 secs ago + | @ 307 days 6 hours 27 mins 59 secs ago + | @ 306 days 6 hours 27 mins 59 secs ago + | @ 2 days 6 hours 27 mins 59 secs ago + | @ 1 day 6 hours 27 mins 59 secs ago + | @ 6 hours 27 mins 59 secs ago + | @ 57 days 17 hours 32 mins 1 sec + | @ 58 days 17 hours 32 mins 1 sec + | @ 362 days 17 hours 32 mins 1 sec + | @ 363 days 17 hours 32 mins 1 sec + | @ 1093 days 17 hours 32 mins 1 sec + | @ 1094 days 17 hours 32 mins 1 sec + | @ 1459 days 17 hours 32 mins 1 sec + | @ 1460 days 17 hours 32 mins 1 sec +(55 rows) + +SELECT '' AS date_trunc_week, date_trunc( 'week', timestamp '2004-02-29 15:44:17.71393' ) AS week_trunc; + date_trunc_week | week_trunc +-----------------+-------------------------- + | Mon Feb 23 00:00:00 2004 +(1 row) + +-- Test casting within a BETWEEN qualifier +SELECT '' AS "54", d1 - timestamp without time zone '1997-01-02' AS diff + FROM TIMESTAMP_TBL + WHERE d1 BETWEEN timestamp without time zone '1902-01-01' + AND timestamp without time zone '2038-01-01' ORDER BY i; + 54 | diff +----+---------------------------------------- + | @ 9863 days ago + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 2 secs + | @ 39 days 17 hours 32 mins 1.4 secs + | @ 39 days 17 hours 32 mins 1.5 secs + | @ 39 days 17 hours 32 mins 1.6 secs + | @ 0 + | @ 3 hours 4 mins 5 secs + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 159 days 17 hours 32 mins 1 sec + | @ 1724 days 18 hours 19 mins 20 secs + | @ 1168 days 8 hours 14 mins 1 sec + | @ 1168 days 13 hours 14 mins 2 secs + | @ 1168 days 12 hours 14 mins 3 secs + | @ 1168 days 3 hours 14 mins 4 secs + | @ 1168 days 2 hours 14 mins 5 secs + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 159 days 18 hours 32 mins 1 sec + | @ 39 days 17 hours 32 mins 1 sec + | @ 40 days 17 hours 32 mins 1 sec + | @ 41 days 17 hours 32 mins 1 sec + | @ 42 days 17 hours 32 mins 1 sec + | @ 43 days 17 hours 32 mins 1 sec + | @ 44 days 17 hours 32 mins 1 sec + | @ 45 days 17 hours 32 mins 1 sec + | @ 45 days 17 hours 32 mins 1 sec + | @ 308 days 6 hours 27 mins 59 secs ago + | @ 307 days 6 hours 27 mins 59 secs ago + | @ 306 days 6 hours 27 mins 59 secs ago + | @ 2 days 6 hours 27 mins 59 secs ago + | @ 1 day 6 hours 27 mins 59 secs ago + | @ 6 hours 27 mins 59 secs ago + | @ 57 days 17 hours 32 mins 1 sec + | @ 58 days 17 hours 32 mins 1 sec + | @ 362 days 17 hours 32 mins 1 sec + | @ 363 days 17 hours 32 mins 1 sec + | @ 1093 days 17 hours 32 mins 1 sec + | @ 1094 days 17 hours 32 mins 1 sec + | @ 1459 days 17 hours 32 mins 1 sec + | @ 1460 days 17 hours 32 mins 1 sec +(55 rows) + +SELECT '' AS "54", d1 as "timestamp", + date_part( 'year', d1) AS year, date_part( 'month', d1) AS month, + date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour, + date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second + FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01' ORDER BY i; + 54 | timestamp | year | month | day | hour | minute | second +----+----------------------------+------+-------+-----+------+--------+-------- + | Thu Jan 01 00:00:00 1970 | 1970 | 1 | 1 | 0 | 0 | 0 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:02 1997 | 1997 | 2 | 10 | 17 | 32 | 2 + | Mon Feb 10 17:32:01.4 1997 | 1997 | 2 | 10 | 17 | 32 | 1.4 + | Mon Feb 10 17:32:01.5 1997 | 1997 | 2 | 10 | 17 | 32 | 1.5 + | Mon Feb 10 17:32:01.6 1997 | 1997 | 2 | 10 | 17 | 32 | 1.6 + | Thu Jan 02 00:00:00 1997 | 1997 | 1 | 2 | 0 | 0 | 0 + | Thu Jan 02 03:04:05 1997 | 1997 | 1 | 2 | 3 | 4 | 5 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Tue Jun 10 17:32:01 1997 | 1997 | 6 | 10 | 17 | 32 | 1 + | Sat Sep 22 18:19:20 2001 | 2001 | 9 | 22 | 18 | 19 | 20 + | Wed Mar 15 08:14:01 2000 | 2000 | 3 | 15 | 8 | 14 | 1 + | Wed Mar 15 13:14:02 2000 | 2000 | 3 | 15 | 13 | 14 | 2 + | Wed Mar 15 12:14:03 2000 | 2000 | 3 | 15 | 12 | 14 | 3 + | Wed Mar 15 03:14:04 2000 | 2000 | 3 | 15 | 3 | 14 | 4 + | Wed Mar 15 02:14:05 2000 | 2000 | 3 | 15 | 2 | 14 | 5 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:00 1997 | 1997 | 2 | 10 | 17 | 32 | 0 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Tue Jun 10 18:32:01 1997 | 1997 | 6 | 10 | 18 | 32 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 2 | 10 | 17 | 32 | 1 + | Tue Feb 11 17:32:01 1997 | 1997 | 2 | 11 | 17 | 32 | 1 + | Wed Feb 12 17:32:01 1997 | 1997 | 2 | 12 | 17 | 32 | 1 + | Thu Feb 13 17:32:01 1997 | 1997 | 2 | 13 | 17 | 32 | 1 + | Fri Feb 14 17:32:01 1997 | 1997 | 2 | 14 | 17 | 32 | 1 + | Sat Feb 15 17:32:01 1997 | 1997 | 2 | 15 | 17 | 32 | 1 + | Sun Feb 16 17:32:01 1997 | 1997 | 2 | 16 | 17 | 32 | 1 + | Sun Feb 16 17:32:01 1997 | 1997 | 2 | 16 | 17 | 32 | 1 + | Wed Feb 28 17:32:01 1996 | 1996 | 2 | 28 | 17 | 32 | 1 + | Thu Feb 29 17:32:01 1996 | 1996 | 2 | 29 | 17 | 32 | 1 + | Fri Mar 01 17:32:01 1996 | 1996 | 3 | 1 | 17 | 32 | 1 + | Mon Dec 30 17:32:01 1996 | 1996 | 12 | 30 | 17 | 32 | 1 + | Tue Dec 31 17:32:01 1996 | 1996 | 12 | 31 | 17 | 32 | 1 + | Wed Jan 01 17:32:01 1997 | 1997 | 1 | 1 | 17 | 32 | 1 + | Fri Feb 28 17:32:01 1997 | 1997 | 2 | 28 | 17 | 32 | 1 + | Sat Mar 01 17:32:01 1997 | 1997 | 3 | 1 | 17 | 32 | 1 + | Tue Dec 30 17:32:01 1997 | 1997 | 12 | 30 | 17 | 32 | 1 + | Wed Dec 31 17:32:01 1997 | 1997 | 12 | 31 | 17 | 32 | 1 + | Fri Dec 31 17:32:01 1999 | 1999 | 12 | 31 | 17 | 32 | 1 + | Sat Jan 01 17:32:01 2000 | 2000 | 1 | 1 | 17 | 32 | 1 + | Sun Dec 31 17:32:01 2000 | 2000 | 12 | 31 | 17 | 32 | 1 + | Mon Jan 01 17:32:01 2001 | 2001 | 1 | 1 | 17 | 32 | 1 +(55 rows) + +SELECT '' AS "54", d1 as "timestamp", + date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec, + date_part( 'usec', d1) AS usec + FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01' ORDER BY i; + 54 | timestamp | quarter | msec | usec +----+----------------------------+---------+-------+---------- + | Thu Jan 01 00:00:00 1970 | 1 | 0 | 0 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:02 1997 | 1 | 2000 | 2000000 + | Mon Feb 10 17:32:01.4 1997 | 1 | 1400 | 1400000 + | Mon Feb 10 17:32:01.5 1997 | 1 | 1500 | 1500000 + | Mon Feb 10 17:32:01.6 1997 | 1 | 1600 | 1600000 + | Thu Jan 02 00:00:00 1997 | 1 | 0 | 0 + | Thu Jan 02 03:04:05 1997 | 1 | 5000 | 5000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Tue Jun 10 17:32:01 1997 | 2 | 1000 | 1000000 + | Sat Sep 22 18:19:20 2001 | 3 | 20000 | 20000000 + | Wed Mar 15 08:14:01 2000 | 1 | 1000 | 1000000 + | Wed Mar 15 13:14:02 2000 | 1 | 2000 | 2000000 + | Wed Mar 15 12:14:03 2000 | 1 | 3000 | 3000000 + | Wed Mar 15 03:14:04 2000 | 1 | 4000 | 4000000 + | Wed Mar 15 02:14:05 2000 | 1 | 5000 | 5000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:00 1997 | 1 | 0 | 0 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Tue Jun 10 18:32:01 1997 | 2 | 1000 | 1000000 + | Mon Feb 10 17:32:01 1997 | 1 | 1000 | 1000000 + | Tue Feb 11 17:32:01 1997 | 1 | 1000 | 1000000 + | Wed Feb 12 17:32:01 1997 | 1 | 1000 | 1000000 + | Thu Feb 13 17:32:01 1997 | 1 | 1000 | 1000000 + | Fri Feb 14 17:32:01 1997 | 1 | 1000 | 1000000 + | Sat Feb 15 17:32:01 1997 | 1 | 1000 | 1000000 + | Sun Feb 16 17:32:01 1997 | 1 | 1000 | 1000000 + | Sun Feb 16 17:32:01 1997 | 1 | 1000 | 1000000 + | Wed Feb 28 17:32:01 1996 | 1 | 1000 | 1000000 + | Thu Feb 29 17:32:01 1996 | 1 | 1000 | 1000000 + | Fri Mar 01 17:32:01 1996 | 1 | 1000 | 1000000 + | Mon Dec 30 17:32:01 1996 | 4 | 1000 | 1000000 + | Tue Dec 31 17:32:01 1996 | 4 | 1000 | 1000000 + | Wed Jan 01 17:32:01 1997 | 1 | 1000 | 1000000 + | Fri Feb 28 17:32:01 1997 | 1 | 1000 | 1000000 + | Sat Mar 01 17:32:01 1997 | 1 | 1000 | 1000000 + | Tue Dec 30 17:32:01 1997 | 4 | 1000 | 1000000 + | Wed Dec 31 17:32:01 1997 | 4 | 1000 | 1000000 + | Fri Dec 31 17:32:01 1999 | 4 | 1000 | 1000000 + | Sat Jan 01 17:32:01 2000 | 1 | 1000 | 1000000 + | Sun Dec 31 17:32:01 2000 | 4 | 1000 | 1000000 + | Mon Jan 01 17:32:01 2001 | 1 | 1000 | 1000000 +(55 rows) + +SELECT '' AS "54", d1 as "timestamp", + date_part( 'isoyear', d1) AS isoyear, date_part( 'week', d1) AS week, + date_part( 'dow', d1) AS dow + FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01' ORDER BY i; + 54 | timestamp | isoyear | week | dow +----+----------------------------+---------+------+----- + | Thu Jan 01 00:00:00 1970 | 1970 | 1 | 4 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:02 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01.4 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01.5 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01.6 1997 | 1997 | 7 | 1 + | Thu Jan 02 00:00:00 1997 | 1997 | 1 | 4 + | Thu Jan 02 03:04:05 1997 | 1997 | 1 | 4 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Tue Jun 10 17:32:01 1997 | 1997 | 24 | 2 + | Sat Sep 22 18:19:20 2001 | 2001 | 38 | 6 + | Wed Mar 15 08:14:01 2000 | 2000 | 11 | 3 + | Wed Mar 15 13:14:02 2000 | 2000 | 11 | 3 + | Wed Mar 15 12:14:03 2000 | 2000 | 11 | 3 + | Wed Mar 15 03:14:04 2000 | 2000 | 11 | 3 + | Wed Mar 15 02:14:05 2000 | 2000 | 11 | 3 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:00 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Tue Jun 10 18:32:01 1997 | 1997 | 24 | 2 + | Mon Feb 10 17:32:01 1997 | 1997 | 7 | 1 + | Tue Feb 11 17:32:01 1997 | 1997 | 7 | 2 + | Wed Feb 12 17:32:01 1997 | 1997 | 7 | 3 + | Thu Feb 13 17:32:01 1997 | 1997 | 7 | 4 + | Fri Feb 14 17:32:01 1997 | 1997 | 7 | 5 + | Sat Feb 15 17:32:01 1997 | 1997 | 7 | 6 + | Sun Feb 16 17:32:01 1997 | 1997 | 7 | 0 + | Sun Feb 16 17:32:01 1997 | 1997 | 7 | 0 + | Wed Feb 28 17:32:01 1996 | 1996 | 9 | 3 + | Thu Feb 29 17:32:01 1996 | 1996 | 9 | 4 + | Fri Mar 01 17:32:01 1996 | 1996 | 9 | 5 + | Mon Dec 30 17:32:01 1996 | 1997 | 1 | 1 + | Tue Dec 31 17:32:01 1996 | 1997 | 1 | 2 + | Wed Jan 01 17:32:01 1997 | 1997 | 1 | 3 + | Fri Feb 28 17:32:01 1997 | 1997 | 9 | 5 + | Sat Mar 01 17:32:01 1997 | 1997 | 9 | 6 + | Tue Dec 30 17:32:01 1997 | 1998 | 1 | 2 + | Wed Dec 31 17:32:01 1997 | 1998 | 1 | 3 + | Fri Dec 31 17:32:01 1999 | 1999 | 52 | 5 + | Sat Jan 01 17:32:01 2000 | 1999 | 52 | 6 + | Sun Dec 31 17:32:01 2000 | 2000 | 52 | 0 + | Mon Jan 01 17:32:01 2001 | 2001 | 1 | 1 +(55 rows) + +-- TO_CHAR() +SELECT '' AS to_char_1, to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_1 | to_char +-----------+------------------------------------------------------------------------------------------ + | + | + | THURSDAY Thursday thursday THU Thu thu JANUARY January january I JAN Jan jan + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | THURSDAY Thursday thursday THU Thu thu JANUARY January january I JAN Jan jan + | THURSDAY Thursday thursday THU Thu thu JANUARY January january I JAN Jan jan + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | TUESDAY Tuesday tuesday TUE Tue tue JUNE June june VI JUN Jun jun + | SATURDAY Saturday saturday SAT Sat sat SEPTEMBER September september IX SEP Sep sep + | WEDNESDAY Wednesday wednesday WED Wed wed MARCH March march III MAR Mar mar + | WEDNESDAY Wednesday wednesday WED Wed wed MARCH March march III MAR Mar mar + | WEDNESDAY Wednesday wednesday WED Wed wed MARCH March march III MAR Mar mar + | WEDNESDAY Wednesday wednesday WED Wed wed MARCH March march III MAR Mar mar + | WEDNESDAY Wednesday wednesday WED Wed wed MARCH March march III MAR Mar mar + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | TUESDAY Tuesday tuesday TUE Tue tue JUNE June june VI JUN Jun jun + | MONDAY Monday monday MON Mon mon FEBRUARY February february II FEB Feb feb + | TUESDAY Tuesday tuesday TUE Tue tue FEBRUARY February february II FEB Feb feb + | WEDNESDAY Wednesday wednesday WED Wed wed FEBRUARY February february II FEB Feb feb + | THURSDAY Thursday thursday THU Thu thu FEBRUARY February february II FEB Feb feb + | FRIDAY Friday friday FRI Fri fri FEBRUARY February february II FEB Feb feb + | SATURDAY Saturday saturday SAT Sat sat FEBRUARY February february II FEB Feb feb + | SUNDAY Sunday sunday SUN Sun sun FEBRUARY February february II FEB Feb feb + | TUESDAY Tuesday tuesday TUE Tue tue FEBRUARY February february II FEB Feb feb + | SATURDAY Saturday saturday SAT Sat sat FEBRUARY February february II FEB Feb feb + | THURSDAY Thursday thursday THU Thu thu FEBRUARY February february II FEB Feb feb + | TUESDAY Tuesday tuesday TUE Tue tue FEBRUARY February february II FEB Feb feb + | SATURDAY Saturday saturday SAT Sat sat FEBRUARY February february II FEB Feb feb + | THURSDAY Thursday thursday THU Thu thu FEBRUARY February february II FEB Feb feb + | TUESDAY Tuesday tuesday TUE Tue tue FEBRUARY February february II FEB Feb feb + | SUNDAY Sunday sunday SUN Sun sun FEBRUARY February february II FEB Feb feb + | SATURDAY Saturday saturday SAT Sat sat FEBRUARY February february II FEB Feb feb + | WEDNESDAY Wednesday wednesday WED Wed wed FEBRUARY February february II FEB Feb feb + | THURSDAY Thursday thursday THU Thu thu FEBRUARY February february II FEB Feb feb + | FRIDAY Friday friday FRI Fri fri MARCH March march III MAR Mar mar + | MONDAY Monday monday MON Mon mon DECEMBER December december XII DEC Dec dec + | TUESDAY Tuesday tuesday TUE Tue tue DECEMBER December december XII DEC Dec dec + | WEDNESDAY Wednesday wednesday WED Wed wed JANUARY January january I JAN Jan jan + | FRIDAY Friday friday FRI Fri fri FEBRUARY February february II FEB Feb feb + | SATURDAY Saturday saturday SAT Sat sat MARCH March march III MAR Mar mar + | TUESDAY Tuesday tuesday TUE Tue tue DECEMBER December december XII DEC Dec dec + | WEDNESDAY Wednesday wednesday WED Wed wed DECEMBER December december XII DEC Dec dec + | FRIDAY Friday friday FRI Fri fri DECEMBER December december XII DEC Dec dec + | SATURDAY Saturday saturday SAT Sat sat JANUARY January january I JAN Jan jan + | SUNDAY Sunday sunday SUN Sun sun DECEMBER December december XII DEC Dec dec + | MONDAY Monday monday MON Mon mon JANUARY January january I JAN Jan jan +(65 rows) + +SELECT '' AS to_char_2, to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_2 | to_char +-----------+-------------------------------------------------------------- + | + | + | THURSDAY Thursday thursday JANUARY January january I + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | THURSDAY Thursday thursday JANUARY January january I + | THURSDAY Thursday thursday JANUARY January january I + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | TUESDAY Tuesday tuesday JUNE June june VI + | SATURDAY Saturday saturday SEPTEMBER September september IX + | WEDNESDAY Wednesday wednesday MARCH March march III + | WEDNESDAY Wednesday wednesday MARCH March march III + | WEDNESDAY Wednesday wednesday MARCH March march III + | WEDNESDAY Wednesday wednesday MARCH March march III + | WEDNESDAY Wednesday wednesday MARCH March march III + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | MONDAY Monday monday FEBRUARY February february II + | TUESDAY Tuesday tuesday JUNE June june VI + | MONDAY Monday monday FEBRUARY February february II + | TUESDAY Tuesday tuesday FEBRUARY February february II + | WEDNESDAY Wednesday wednesday FEBRUARY February february II + | THURSDAY Thursday thursday FEBRUARY February february II + | FRIDAY Friday friday FEBRUARY February february II + | SATURDAY Saturday saturday FEBRUARY February february II + | SUNDAY Sunday sunday FEBRUARY February february II + | TUESDAY Tuesday tuesday FEBRUARY February february II + | SATURDAY Saturday saturday FEBRUARY February february II + | THURSDAY Thursday thursday FEBRUARY February february II + | TUESDAY Tuesday tuesday FEBRUARY February february II + | SATURDAY Saturday saturday FEBRUARY February february II + | THURSDAY Thursday thursday FEBRUARY February february II + | TUESDAY Tuesday tuesday FEBRUARY February february II + | SUNDAY Sunday sunday FEBRUARY February february II + | SATURDAY Saturday saturday FEBRUARY February february II + | WEDNESDAY Wednesday wednesday FEBRUARY February february II + | THURSDAY Thursday thursday FEBRUARY February february II + | FRIDAY Friday friday MARCH March march III + | MONDAY Monday monday DECEMBER December december XII + | TUESDAY Tuesday tuesday DECEMBER December december XII + | WEDNESDAY Wednesday wednesday JANUARY January january I + | FRIDAY Friday friday FEBRUARY February february II + | SATURDAY Saturday saturday MARCH March march III + | TUESDAY Tuesday tuesday DECEMBER December december XII + | WEDNESDAY Wednesday wednesday DECEMBER December december XII + | FRIDAY Friday friday DECEMBER December december XII + | SATURDAY Saturday saturday JANUARY January january I + | SUNDAY Sunday sunday DECEMBER December december XII + | MONDAY Monday monday JANUARY January january I +(65 rows) + +SELECT '' AS to_char_3, to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_3 | to_char +-----------+-------------------------------------------------- + | + | + | 1,970 1970 970 70 0 20 1 01 01 001 01 5 2440588 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 01 01 002 02 5 2450451 + | 1,997 1997 997 97 7 20 1 01 01 002 02 5 2450451 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 2 06 23 161 10 3 2450610 + | 2,001 2001 001 01 1 21 3 09 38 265 22 7 2452175 + | 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619 + | 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619 + | 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619 + | 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619 + | 2,000 2000 000 00 0 20 1 03 11 075 15 4 2451619 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 2 06 23 161 10 3 2450610 + | 1,997 1997 997 97 7 20 1 02 06 041 10 2 2450490 + | 1,997 1997 997 97 7 20 1 02 06 042 11 3 2450491 + | 1,997 1997 997 97 7 20 1 02 07 043 12 4 2450492 + | 1,997 1997 997 97 7 20 1 02 07 044 13 5 2450493 + | 1,997 1997 997 97 7 20 1 02 07 045 14 6 2450494 + | 1,997 1997 997 97 7 20 1 02 07 046 15 7 2450495 + | 1,997 1997 997 97 7 20 1 02 07 047 16 1 2450496 + | 0,097 0097 097 97 7 -01 1 02 07 047 16 3 1686042 + | 0,097 0097 097 97 7 01 1 02 07 047 16 7 1756536 + | 0,597 0597 597 97 7 06 1 02 07 047 16 5 1939157 + | 1,097 1097 097 97 7 11 1 02 07 047 16 3 2121778 + | 1,697 1697 697 97 7 17 1 02 07 047 16 7 2340924 + | 1,797 1797 797 97 7 18 1 02 07 047 16 5 2377448 + | 1,897 1897 897 97 7 19 1 02 07 047 16 3 2413972 + | 1,997 1997 997 97 7 20 1 02 07 047 16 1 2450496 + | 2,097 2097 097 97 7 21 1 02 07 047 16 7 2487021 + | 1,996 1996 996 96 6 20 1 02 09 059 28 4 2450142 + | 1,996 1996 996 96 6 20 1 02 09 060 29 5 2450143 + | 1,996 1996 996 96 6 20 1 03 09 061 01 6 2450144 + | 1,996 1996 996 96 6 20 4 12 53 365 30 2 2450448 + | 1,996 1996 996 96 6 20 4 12 53 366 31 3 2450449 + | 1,997 1997 997 97 7 20 1 01 01 001 01 4 2450450 + | 1,997 1997 997 97 7 20 1 02 09 059 28 6 2450508 + | 1,997 1997 997 97 7 20 1 03 09 060 01 7 2450509 + | 1,997 1997 997 97 7 20 4 12 52 364 30 3 2450813 + | 1,997 1997 997 97 7 20 4 12 53 365 31 4 2450814 + | 1,999 1999 999 99 9 20 4 12 53 365 31 6 2451544 + | 2,000 2000 000 00 0 20 1 01 01 001 01 7 2451545 + | 2,000 2000 000 00 0 20 4 12 53 366 31 1 2451910 + | 2,001 2001 001 01 1 21 1 01 01 001 01 2 2451911 +(65 rows) + +SELECT '' AS to_char_4, to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_4 | to_char +-----------+------------------------------------------------- + | + | + | 1,970 1970 970 70 0 20 1 1 1 1 1 5 2440588 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 1 1 2 2 5 2450451 + | 1,997 1997 997 97 7 20 1 1 1 2 2 5 2450451 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 2 6 23 161 10 3 2450610 + | 2,001 2001 1 1 1 21 3 9 38 265 22 7 2452175 + | 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619 + | 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619 + | 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619 + | 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619 + | 2,000 2000 0 0 0 20 1 3 11 75 15 4 2451619 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 2 6 23 161 10 3 2450610 + | 1,997 1997 997 97 7 20 1 2 6 41 10 2 2450490 + | 1,997 1997 997 97 7 20 1 2 6 42 11 3 2450491 + | 1,997 1997 997 97 7 20 1 2 7 43 12 4 2450492 + | 1,997 1997 997 97 7 20 1 2 7 44 13 5 2450493 + | 1,997 1997 997 97 7 20 1 2 7 45 14 6 2450494 + | 1,997 1997 997 97 7 20 1 2 7 46 15 7 2450495 + | 1,997 1997 997 97 7 20 1 2 7 47 16 1 2450496 + | 0,097 97 97 97 7 -1 1 2 7 47 16 3 1686042 + | 0,097 97 97 97 7 1 1 2 7 47 16 7 1756536 + | 0,597 597 597 97 7 6 1 2 7 47 16 5 1939157 + | 1,097 1097 97 97 7 11 1 2 7 47 16 3 2121778 + | 1,697 1697 697 97 7 17 1 2 7 47 16 7 2340924 + | 1,797 1797 797 97 7 18 1 2 7 47 16 5 2377448 + | 1,897 1897 897 97 7 19 1 2 7 47 16 3 2413972 + | 1,997 1997 997 97 7 20 1 2 7 47 16 1 2450496 + | 2,097 2097 97 97 7 21 1 2 7 47 16 7 2487021 + | 1,996 1996 996 96 6 20 1 2 9 59 28 4 2450142 + | 1,996 1996 996 96 6 20 1 2 9 60 29 5 2450143 + | 1,996 1996 996 96 6 20 1 3 9 61 1 6 2450144 + | 1,996 1996 996 96 6 20 4 12 53 365 30 2 2450448 + | 1,996 1996 996 96 6 20 4 12 53 366 31 3 2450449 + | 1,997 1997 997 97 7 20 1 1 1 1 1 4 2450450 + | 1,997 1997 997 97 7 20 1 2 9 59 28 6 2450508 + | 1,997 1997 997 97 7 20 1 3 9 60 1 7 2450509 + | 1,997 1997 997 97 7 20 4 12 52 364 30 3 2450813 + | 1,997 1997 997 97 7 20 4 12 53 365 31 4 2450814 + | 1,999 1999 999 99 9 20 4 12 53 365 31 6 2451544 + | 2,000 2000 0 0 0 20 1 1 1 1 1 7 2451545 + | 2,000 2000 0 0 0 20 4 12 53 366 31 1 2451910 + | 2,001 2001 1 1 1 21 1 1 1 1 1 2 2451911 +(65 rows) + +SELECT '' AS to_char_5, to_char(d1, 'HH HH12 HH24 MI SS SSSS') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_5 | to_char +-----------+---------------------- + | + | + | 12 12 00 00 00 0 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 02 63122 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 12 12 00 00 00 0 + | 03 03 03 04 05 11045 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 06 06 18 19 20 65960 + | 08 08 08 14 01 29641 + | 01 01 13 14 02 47642 + | 12 12 12 14 03 44043 + | 03 03 03 14 04 11644 + | 02 02 02 14 05 8045 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 00 63120 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 06 06 18 32 01 66721 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 + | 05 05 17 32 01 63121 +(65 rows) + +SELECT '' AS to_char_6, to_char(d1, E'"HH:MI:SS is" HH:MI:SS "\\"text between quote marks\\""') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_6 | to_char +-----------+------------------------------------------------- + | + | + | HH:MI:SS is 12:00:00 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:02 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 12:00:00 "text between quote marks" + | HH:MI:SS is 03:04:05 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 06:19:20 "text between quote marks" + | HH:MI:SS is 08:14:01 "text between quote marks" + | HH:MI:SS is 01:14:02 "text between quote marks" + | HH:MI:SS is 12:14:03 "text between quote marks" + | HH:MI:SS is 03:14:04 "text between quote marks" + | HH:MI:SS is 02:14:05 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:00 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 06:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" + | HH:MI:SS is 05:32:01 "text between quote marks" +(65 rows) + +SELECT '' AS to_char_7, to_char(d1, 'HH24--text--MI--text--SS') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_7 | to_char +-----------+------------------------ + | + | + | 00--text--00--text--00 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--02 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 00--text--00--text--00 + | 03--text--04--text--05 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 18--text--19--text--20 + | 08--text--14--text--01 + | 13--text--14--text--02 + | 12--text--14--text--03 + | 03--text--14--text--04 + | 02--text--14--text--05 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--00 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 18--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 + | 17--text--32--text--01 +(65 rows) + +SELECT '' AS to_char_8, to_char(d1, 'YYYYTH YYYYth Jth') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_8 | to_char +-----------+------------------------- + | + | + | 1970TH 1970th 2440588th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450451st + | 1997TH 1997th 2450451st + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450610th + | 2001ST 2001st 2452175th + | 2000TH 2000th 2451619th + | 2000TH 2000th 2451619th + | 2000TH 2000th 2451619th + | 2000TH 2000th 2451619th + | 2000TH 2000th 2451619th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450610th + | 1997TH 1997th 2450490th + | 1997TH 1997th 2450491st + | 1997TH 1997th 2450492nd + | 1997TH 1997th 2450493rd + | 1997TH 1997th 2450494th + | 1997TH 1997th 2450495th + | 1997TH 1997th 2450496th + | 0097TH 0097th 1686042nd + | 0097TH 0097th 1756536th + | 0597TH 0597th 1939157th + | 1097TH 1097th 2121778th + | 1697TH 1697th 2340924th + | 1797TH 1797th 2377448th + | 1897TH 1897th 2413972nd + | 1997TH 1997th 2450496th + | 2097TH 2097th 2487021st + | 1996TH 1996th 2450142nd + | 1996TH 1996th 2450143rd + | 1996TH 1996th 2450144th + | 1996TH 1996th 2450448th + | 1996TH 1996th 2450449th + | 1997TH 1997th 2450450th + | 1997TH 1997th 2450508th + | 1997TH 1997th 2450509th + | 1997TH 1997th 2450813th + | 1997TH 1997th 2450814th + | 1999TH 1999th 2451544th + | 2000TH 2000th 2451545th + | 2000TH 2000th 2451910th + | 2001ST 2001st 2451911th +(65 rows) + +SELECT '' AS to_char_9, to_char(d1, 'YYYY A.D. YYYY a.d. YYYY bc HH:MI:SS P.M. HH:MI:SS p.m. HH:MI:SS pm') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_9 | to_char +-----------+--------------------------------------------------------------------- + | + | + | 1970 A.D. 1970 a.d. 1970 ad 12:00:00 A.M. 12:00:00 a.m. 12:00:00 am + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:02 P.M. 05:32:02 p.m. 05:32:02 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 12:00:00 A.M. 12:00:00 a.m. 12:00:00 am + | 1997 A.D. 1997 a.d. 1997 ad 03:04:05 A.M. 03:04:05 a.m. 03:04:05 am + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 2001 A.D. 2001 a.d. 2001 ad 06:19:20 P.M. 06:19:20 p.m. 06:19:20 pm + | 2000 A.D. 2000 a.d. 2000 ad 08:14:01 A.M. 08:14:01 a.m. 08:14:01 am + | 2000 A.D. 2000 a.d. 2000 ad 01:14:02 P.M. 01:14:02 p.m. 01:14:02 pm + | 2000 A.D. 2000 a.d. 2000 ad 12:14:03 P.M. 12:14:03 p.m. 12:14:03 pm + | 2000 A.D. 2000 a.d. 2000 ad 03:14:04 A.M. 03:14:04 a.m. 03:14:04 am + | 2000 A.D. 2000 a.d. 2000 ad 02:14:05 A.M. 02:14:05 a.m. 02:14:05 am + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:00 P.M. 05:32:00 p.m. 05:32:00 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 06:32:01 P.M. 06:32:01 p.m. 06:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 0097 B.C. 0097 b.c. 0097 bc 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 0097 A.D. 0097 a.d. 0097 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 0597 A.D. 0597 a.d. 0597 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1097 A.D. 1097 a.d. 1097 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1697 A.D. 1697 a.d. 1697 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1797 A.D. 1797 a.d. 1797 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1897 A.D. 1897 a.d. 1897 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 2097 A.D. 2097 a.d. 2097 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1996 A.D. 1996 a.d. 1996 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1997 A.D. 1997 a.d. 1997 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 1999 A.D. 1999 a.d. 1999 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 2000 A.D. 2000 a.d. 2000 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 2000 A.D. 2000 a.d. 2000 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm + | 2001 A.D. 2001 a.d. 2001 ad 05:32:01 P.M. 05:32:01 p.m. 05:32:01 pm +(65 rows) + +SELECT '' AS to_char_10, to_char(d1, 'IYYY IYY IY I IW IDDD ID') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_10 | to_char +------------+------------------------ + | + | + | 1970 970 70 0 01 004 4 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 01 004 4 + | 1997 997 97 7 01 004 4 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 24 163 2 + | 2001 001 01 1 38 265 6 + | 2000 000 00 0 11 073 3 + | 2000 000 00 0 11 073 3 + | 2000 000 00 0 11 073 3 + | 2000 000 00 0 11 073 3 + | 2000 000 00 0 11 073 3 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 24 163 2 + | 1997 997 97 7 07 043 1 + | 1997 997 97 7 07 044 2 + | 1997 997 97 7 07 045 3 + | 1997 997 97 7 07 046 4 + | 1997 997 97 7 07 047 5 + | 1997 997 97 7 07 048 6 + | 1997 997 97 7 07 049 7 + | 0097 097 97 7 07 044 2 + | 0097 097 97 7 07 048 6 + | 0597 597 97 7 07 046 4 + | 1097 097 97 7 07 044 2 + | 1697 697 97 7 07 048 6 + | 1797 797 97 7 07 046 4 + | 1897 897 97 7 07 044 2 + | 1997 997 97 7 07 049 7 + | 2097 097 97 7 07 048 6 + | 1996 996 96 6 09 059 3 + | 1996 996 96 6 09 060 4 + | 1996 996 96 6 09 061 5 + | 1997 997 97 7 01 001 1 + | 1997 997 97 7 01 002 2 + | 1997 997 97 7 01 003 3 + | 1997 997 97 7 09 061 5 + | 1997 997 97 7 09 062 6 + | 1998 998 98 8 01 002 2 + | 1998 998 98 8 01 003 3 + | 1999 999 99 9 52 362 5 + | 1999 999 99 9 52 363 6 + | 2000 000 00 0 52 364 7 + | 2001 001 01 1 01 001 1 +(65 rows) + +SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID') + FROM TIMESTAMP_TBL ORDER BY i; + to_char_11 | to_char +------------+------------------------ + | + | + | 1970 970 70 0 1 4 4 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 1 4 4 + | 1997 997 97 7 1 4 4 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 24 163 2 + | 2001 1 1 1 38 265 6 + | 2000 0 0 0 11 73 3 + | 2000 0 0 0 11 73 3 + | 2000 0 0 0 11 73 3 + | 2000 0 0 0 11 73 3 + | 2000 0 0 0 11 73 3 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 24 163 2 + | 1997 997 97 7 7 43 1 + | 1997 997 97 7 7 44 2 + | 1997 997 97 7 7 45 3 + | 1997 997 97 7 7 46 4 + | 1997 997 97 7 7 47 5 + | 1997 997 97 7 7 48 6 + | 1997 997 97 7 7 49 7 + | 97 97 97 7 7 44 2 + | 97 97 97 7 7 48 6 + | 597 597 97 7 7 46 4 + | 1097 97 97 7 7 44 2 + | 1697 697 97 7 7 48 6 + | 1797 797 97 7 7 46 4 + | 1897 897 97 7 7 44 2 + | 1997 997 97 7 7 49 7 + | 2097 97 97 7 7 48 6 + | 1996 996 96 6 9 59 3 + | 1996 996 96 6 9 60 4 + | 1996 996 96 6 9 61 5 + | 1997 997 97 7 1 1 1 + | 1997 997 97 7 1 2 2 + | 1997 997 97 7 1 3 3 + | 1997 997 97 7 9 61 5 + | 1997 997 97 7 9 62 6 + | 1998 998 98 8 1 2 2 + | 1998 998 98 8 1 3 3 + | 1999 999 99 9 52 362 5 + | 1999 999 99 9 52 363 6 + | 2000 0 0 0 52 364 7 + | 2001 1 1 1 1 1 1 +(65 rows) + +-- timestamp numeric fields constructor +SELECT make_timestamp(2014,12,28,6,30,45.887); + make_timestamp +------------------------------ + Sun Dec 28 06:30:45.887 2014 +(1 row) + +DROP TABLE TIMESTAMP_TBL; diff --git a/src/postgres/src/test/regress/sql/timestamp.sql b/src/postgres/src/test/regress/sql/timestamp.sql index b7957cbb9aa8..652b87cc03cc 100644 --- a/src/postgres/src/test/regress/sql/timestamp.sql +++ b/src/postgres/src/test/regress/sql/timestamp.sql @@ -2,7 +2,7 @@ -- TIMESTAMP -- -CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone); +CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone PRIMARY KEY); -- Test shorthand input values -- We can't just "select" the results since they aren't constants; test for @@ -16,8 +16,6 @@ CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone); INSERT INTO TIMESTAMP_TBL VALUES ('now'); SELECT pg_sleep(0.1); -BEGIN; - INSERT INTO TIMESTAMP_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('today'); INSERT INTO TIMESTAMP_TBL VALUES ('yesterday'); @@ -26,25 +24,20 @@ INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu'); -SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today'; -SELECT count(*) AS Three FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow'; -SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday'; -SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now'; - -COMMIT; +SElECT COUNT(*) FROM TIMESTAMP_TBL; -DELETE FROM TIMESTAMP_TBL; +DROP TABLE TIMESTAMP_TBL; +CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone PRIMARY KEY); -- verify uniform transaction time within transaction block -BEGIN; INSERT INTO TIMESTAMP_TBL VALUES ('now'); SELECT pg_sleep(0.1); INSERT INTO TIMESTAMP_TBL VALUES ('now'); SELECT pg_sleep(0.1); -SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now'; -COMMIT; +SELECT count(*) FROM TIMESTAMP_TBL ORDER BY d1; -DELETE FROM TIMESTAMP_TBL; +DROP TABLE TIMESTAMP_TBL; +CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone PRIMARY KEY); -- Special values INSERT INTO TIMESTAMP_TBL VALUES ('-infinity'); @@ -141,7 +134,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Jan 01 17:32:01 2001'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097'); INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC'); -SELECT '' AS "64", d1 FROM TIMESTAMP_TBL; +SELECT '' AS "64", d1 FROM TIMESTAMP_TBL ORDER BY d1; -- Check behavior at the lower boundary of the timestamp range SELECT '4714-11-24 00:00:00 BC'::timestamp; @@ -196,37 +189,37 @@ SELECT '' AS "54", d1 as "timestamp", -- TO_CHAR() SELECT '' AS to_char_1, to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_2, to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_3, to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_4, to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_5, to_char(d1, 'HH HH12 HH24 MI SS SSSS') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_6, to_char(d1, E'"HH:MI:SS is" HH:MI:SS "\\"text between quote marks\\""') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_7, to_char(d1, 'HH24--text--MI--text--SS') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_8, to_char(d1, 'YYYYTH YYYYth Jth') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_9, to_char(d1, 'YYYY A.D. YYYY a.d. YYYY bc HH:MI:SS P.M. HH:MI:SS p.m. HH:MI:SS pm') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_10, to_char(d1, 'IYYY IYY IY I IW IDDD ID') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID') - FROM TIMESTAMP_TBL; + FROM TIMESTAMP_TBL ORDER BY d1; -- timestamp numeric fields constructor SELECT make_timestamp(2014,12,28,6,30,45.887); diff --git a/src/postgres/src/test/regress/sql/yb_timestamp.sql b/src/postgres/src/test/regress/sql/yb_timestamp.sql new file mode 100644 index 000000000000..24a9c49ddb7d --- /dev/null +++ b/src/postgres/src/test/regress/sql/yb_timestamp.sql @@ -0,0 +1,192 @@ +-- +-- TIMESTAMP +-- + +CREATE TABLE TIMESTAMP_TBL (i int PRIMARY KEY, d1 timestamp(2) without time zone); + +-- Special values +INSERT INTO TIMESTAMP_TBL VALUES (10, '-infinity'); +INSERT INTO TIMESTAMP_TBL VALUES (20, 'infinity'); +INSERT INTO TIMESTAMP_TBL VALUES (30, 'epoch'); +-- Obsolete special values +INSERT INTO TIMESTAMP_TBL VALUES (40, 'invalid'); +INSERT INTO TIMESTAMP_TBL VALUES (50, 'undefined'); +INSERT INTO TIMESTAMP_TBL VALUES (60, 'current'); + +-- Postgres v6.0 standard output format +INSERT INTO TIMESTAMP_TBL VALUES (70, 'Mon Feb 10 17:32:01 1997 PST'); + +-- Variations on Postgres v6.1 standard output format +INSERT INTO TIMESTAMP_TBL VALUES (75, 'Mon Feb 10 17:32:01.000001 1997 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (80, 'Mon Feb 10 17:32:01.999999 1997 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (90, 'Mon Feb 10 17:32:01.4 1997 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (100, 'Mon Feb 10 17:32:01.5 1997 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (110, 'Mon Feb 10 17:32:01.6 1997 PST'); + +-- ISO 8601 format +INSERT INTO TIMESTAMP_TBL VALUES (120, '1997-01-02'); +INSERT INTO TIMESTAMP_TBL VALUES (130, '1997-01-02 03:04:05'); +INSERT INTO TIMESTAMP_TBL VALUES (140, '1997-02-10 17:32:01-08'); +INSERT INTO TIMESTAMP_TBL VALUES (150, '1997-02-10 17:32:01-0800'); +INSERT INTO TIMESTAMP_TBL VALUES (160, '1997-02-10 17:32:01 -08:00'); +INSERT INTO TIMESTAMP_TBL VALUES (170, '19970210 173201 -0800'); +INSERT INTO TIMESTAMP_TBL VALUES (180, '1997-06-10 17:32:01 -07:00'); +INSERT INTO TIMESTAMP_TBL VALUES (190, '2001-09-22T18:19:20'); + +-- POSIX format (note that the timezone abbrev is just decoration here) +INSERT INTO TIMESTAMP_TBL VALUES (200, '2000-03-15 08:14:01 GMT+8'); +INSERT INTO TIMESTAMP_TBL VALUES (210, '2000-03-15 13:14:02 GMT-1'); +INSERT INTO TIMESTAMP_TBL VALUES (220, '2000-03-15 12:14:03 GMT-2'); +INSERT INTO TIMESTAMP_TBL VALUES (230, '2000-03-15 03:14:04 PST+8'); +INSERT INTO TIMESTAMP_TBL VALUES (240, '2000-03-15 02:14:05 MST+7:00'); + +-- Variations for acceptable input formats +INSERT INTO TIMESTAMP_TBL VALUES (250, 'Feb 10 17:32:01 1997 -0800'); +INSERT INTO TIMESTAMP_TBL VALUES (260, 'Feb 10 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (270, 'Feb 10 5:32PM 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (280, '1997/02/10 17:32:01-0800'); +INSERT INTO TIMESTAMP_TBL VALUES (290, '1997-02-10 17:32:01 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (300, 'Feb-10-1997 17:32:01 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (310, '02-10-1997 17:32:01 PST'); +INSERT INTO TIMESTAMP_TBL VALUES (320, '19970210 173201 PST'); +set datestyle to ymd; +INSERT INTO TIMESTAMP_TBL VALUES (330, '97FEB10 5:32:01PM UTC'); +INSERT INTO TIMESTAMP_TBL VALUES (340, '97/02/10 17:32:01 UTC'); +reset datestyle; +INSERT INTO TIMESTAMP_TBL VALUES (350, '1997.041 17:32:01 UTC'); +INSERT INTO TIMESTAMP_TBL VALUES (360, '19970210 173201 America/New_York'); +-- this fails (even though TZ is a no-op, we still look it up) +INSERT INTO TIMESTAMP_TBL VALUES (370, '19970710 173201 America/Does_not_exist'); + +-- Check date conversion and date arithmetic +INSERT INTO TIMESTAMP_TBL VALUES (380, '1997-06-10 18:32:01 PDT'); + +INSERT INTO TIMESTAMP_TBL VALUES (390, 'Feb 10 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (400, 'Feb 11 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (410, 'Feb 12 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (420, 'Feb 13 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (430, 'Feb 14 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (440, 'Feb 15 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (450, 'Feb 16 17:32:01 1997'); + +INSERT INTO TIMESTAMP_TBL VALUES (460, 'Feb 16 17:32:01 0097 BC'); +INSERT INTO TIMESTAMP_TBL VALUES (470, 'Feb 16 17:32:01 0097'); +INSERT INTO TIMESTAMP_TBL VALUES (480, 'Feb 16 17:32:01 0597'); +INSERT INTO TIMESTAMP_TBL VALUES (490, 'Feb 16 17:32:01 1097'); +INSERT INTO TIMESTAMP_TBL VALUES (500, 'Feb 16 17:32:01 1697'); +INSERT INTO TIMESTAMP_TBL VALUES (510, 'Feb 16 17:32:01 1797'); +INSERT INTO TIMESTAMP_TBL VALUES (520, 'Feb 16 17:32:01 1897'); +INSERT INTO TIMESTAMP_TBL VALUES (530, 'Feb 16 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (540, 'Feb 16 17:32:01 2097'); + +INSERT INTO TIMESTAMP_TBL VALUES (550, 'Feb 28 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (560, 'Feb 29 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (570, 'Mar 01 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (580, 'Dec 30 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (590, 'Dec 31 17:32:01 1996'); +INSERT INTO TIMESTAMP_TBL VALUES (600, 'Jan 01 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (610, 'Feb 28 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (620, 'Feb 29 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (630, 'Mar 01 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (640, 'Dec 30 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (650, 'Dec 31 17:32:01 1997'); +INSERT INTO TIMESTAMP_TBL VALUES (660, 'Dec 31 17:32:01 1999'); +INSERT INTO TIMESTAMP_TBL VALUES (670, 'Jan 01 17:32:01 2000'); +INSERT INTO TIMESTAMP_TBL VALUES (680, 'Dec 31 17:32:01 2000'); +INSERT INTO TIMESTAMP_TBL VALUES (690, 'Jan 01 17:32:01 2001'); + +-- Currently unsupported syntax and ranges +INSERT INTO TIMESTAMP_TBL VALUES (700, 'Feb 16 17:32:01 -0097'); +INSERT INTO TIMESTAMP_TBL VALUES (710, 'Feb 16 17:32:01 5097 BC'); + +SELECT '' AS "64", d1 FROM TIMESTAMP_TBL ORDER BY i; + +-- Check behavior at the lower boundary of the timestamp range +SELECT '4714-11-24 00:00:00 BC'::timestamp; +SELECT '4714-11-23 23:59:59 BC'::timestamp; -- out of range +-- The upper boundary differs between integer and float timestamps, so no check + +-- Demonstrate functions and operators +SELECT '' AS "48", d1 FROM TIMESTAMP_TBL + WHERE d1 > timestamp without time zone '1997-01-02' ORDER BY i; + +SELECT '' AS "15", d1 FROM TIMESTAMP_TBL + WHERE d1 < timestamp without time zone '1997-01-02' ORDER BY i; + +SELECT '' AS one, d1 FROM TIMESTAMP_TBL + WHERE d1 = timestamp without time zone '1997-01-02' ORDER BY i; + +SELECT '' AS "63", d1 FROM TIMESTAMP_TBL + WHERE d1 != timestamp without time zone '1997-01-02' ORDER BY i; + +SELECT '' AS "16", d1 FROM TIMESTAMP_TBL + WHERE d1 <= timestamp without time zone '1997-01-02' ORDER BY i; + +SELECT '' AS "49", d1 FROM TIMESTAMP_TBL + WHERE d1 >= timestamp without time zone '1997-01-02' ORDER BY i; + +SELECT '' AS "54", d1 - timestamp without time zone '1997-01-02' AS diff + FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01' ORDER BY i; + +SELECT '' AS date_trunc_week, date_trunc( 'week', timestamp '2004-02-29 15:44:17.71393' ) AS week_trunc; + +-- Test casting within a BETWEEN qualifier +SELECT '' AS "54", d1 - timestamp without time zone '1997-01-02' AS diff + FROM TIMESTAMP_TBL + WHERE d1 BETWEEN timestamp without time zone '1902-01-01' + AND timestamp without time zone '2038-01-01' ORDER BY i; + +SELECT '' AS "54", d1 as "timestamp", + date_part( 'year', d1) AS year, date_part( 'month', d1) AS month, + date_part( 'day', d1) AS day, date_part( 'hour', d1) AS hour, + date_part( 'minute', d1) AS minute, date_part( 'second', d1) AS second + FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01' ORDER BY i; + +SELECT '' AS "54", d1 as "timestamp", + date_part( 'quarter', d1) AS quarter, date_part( 'msec', d1) AS msec, + date_part( 'usec', d1) AS usec + FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01' ORDER BY i; + +SELECT '' AS "54", d1 as "timestamp", + date_part( 'isoyear', d1) AS isoyear, date_part( 'week', d1) AS week, + date_part( 'dow', d1) AS dow + FROM TIMESTAMP_TBL WHERE d1 BETWEEN '1902-01-01' AND '2038-01-01' ORDER BY i; + +-- TO_CHAR() +SELECT '' AS to_char_1, to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_2, to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_3, to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_4, to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_5, to_char(d1, 'HH HH12 HH24 MI SS SSSS') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_6, to_char(d1, E'"HH:MI:SS is" HH:MI:SS "\\"text between quote marks\\""') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_7, to_char(d1, 'HH24--text--MI--text--SS') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_8, to_char(d1, 'YYYYTH YYYYth Jth') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_9, to_char(d1, 'YYYY A.D. YYYY a.d. YYYY bc HH:MI:SS P.M. HH:MI:SS p.m. HH:MI:SS pm') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_10, to_char(d1, 'IYYY IYY IY I IW IDDD ID') + FROM TIMESTAMP_TBL ORDER BY i; + +SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID') + FROM TIMESTAMP_TBL ORDER BY i; + +-- timestamp numeric fields constructor +SELECT make_timestamp(2014,12,28,6,30,45.887); + +DROP TABLE TIMESTAMP_TBL; diff --git a/src/postgres/src/test/regress/yb_serial_schedule b/src/postgres/src/test/regress/yb_serial_schedule index 3e31dbc08321..fcda52a888dd 100644 --- a/src/postgres/src/test/regress/yb_serial_schedule +++ b/src/postgres/src/test/regress/yb_serial_schedule @@ -6,10 +6,10 @@ test: yb_bytea test: yb_text test: yb_oid test: yb_int2 -# TODO: re-enable these after ASAN/UBSAN is fixed. test: yb_int4 test: yb_int8 test: yb_int2_array test: yb_int4_array test: yb_float4 test: yb_float8 +test: yb_timestamp diff --git a/src/yb/docdb/CMakeLists.txt b/src/yb/docdb/CMakeLists.txt index ccd731a2446d..3f5d31047d33 100644 --- a/src/yb/docdb/CMakeLists.txt +++ b/src/yb/docdb/CMakeLists.txt @@ -69,6 +69,16 @@ ADD_YB_LIBRARY(yb_docdb DEPS ${DOCDB_DEPS}) cotire(yb_docdb) +# Ensure protobuf headers we depend on are generated prior to building DocDB. +add_dependencies( + yb_docdb + gen_src_yb_master_master_proto + gen_src_yb_rpc_rpc_header_proto + gen_src_yb_tablet_metadata_proto + gen_src_yb_tablet_tablet_proto + gen_src_yb_tserver_tserver_proto + ) + # A library with common code shared between DocDB tests. set(DOCDB_TEST_COMMON_SRCS docdb_test_util.cc diff --git a/src/yb/tools/CMakeLists.txt b/src/yb/tools/CMakeLists.txt index be454665b53a..32b9f8a0fd32 100644 --- a/src/yb/tools/CMakeLists.txt +++ b/src/yb/tools/CMakeLists.txt @@ -96,6 +96,9 @@ target_link_libraries(ysck tserver_service_proto ${YB_BASE_LIBS} ) +add_dependencies( + ysck + gen_src_yb_consensus_log_proto) add_executable(yb-ysck yb-ysck.cc) target_link_libraries(yb-ysck diff --git a/src/yb/util/bfpg/CMakeLists.txt b/src/yb/util/bfpg/CMakeLists.txt index 5048abc5cffc..1f1a89771c8a 100644 --- a/src/yb/util/bfpg/CMakeLists.txt +++ b/src/yb/util/bfpg/CMakeLists.txt @@ -44,6 +44,11 @@ ADD_YB_LIBRARY(yb_bfpg # Make sure code-generator is built before yb_bfpg library. add_dependencies(yb_bfpg bfpg_codegen) +# Also make sure that the protobuf headers we depend on here are generated. +add_dependencies(yb_bfpg bfpg_codegen + gen_src_yb_common_pgsql_protocol_proto + gen_src_yb_common_ql_protocol_proto + ) # Build the test cases. set(YB_TEST_LINK_LIBS yb_bfpg ${YB_MIN_TEST_LIBS} yb_common) diff --git a/src/yb/util/status.h b/src/yb/util/status.h index 32a578a470ca..0691af90386f 100644 --- a/src/yb/util/status.h +++ b/src/yb/util/status.h @@ -324,9 +324,12 @@ inline std::ostream& operator<<(std::ostream& out, const Status& status) { // Utility macros to perform the appropriate check. If the check fails, // returns the specified (error) Status, with the given message. -#define SCHECK_OP(var1, op, var2, type, msg) \ - do { \ - if (PREDICT_FALSE(!((var1)op(var2)))) return STATUS(type, msg); \ +#define SCHECK_OP(var1, op, var2, type, msg) \ + do { \ + auto v1_tmp = (var1); \ + auto v2_tmp = (var2); \ + if (PREDICT_FALSE(!((v1_tmp)op(v2_tmp)))) return STATUS(type, \ + yb::Format("$0: $1 vs. $2", (msg), v1_tmp, v2_tmp)); \ } while (0) #define SCHECK(expr, type, msg) SCHECK_OP(expr, ==, true, type, msg) #define SCHECK_EQ(var1, var2, type, msg) SCHECK_OP(var1, ==, var2, type, msg)