在psql 12中以文本格式比较时间

问题描述

// disable this if you're already using the command below.
// This can cause `command` to be defined twice and return a constant value error.

// const commandFiles = fs
//     .readdirsync('./commands/')
//     .filter(file => file.endsWith('.js'));
// for(const file of commandFiles){
//     const command = require(`./commands/${file}`);
//     client.commands.set(command.name,command);
// }

client.on('ready',() => {
 // `client.on()` should be better
 console.log('ChatSlowMode is Online!');
});

client.on('message',(message) => {
 // Check if message doesn't starts with `prefix` instead,or it will stop your code.
 if (!message.content.startsWith(prefix) || message.author.bot) return;

 const command = message.content
  .slice(prefix.length)
  .toLowerCase()
  .split(' ')[0]
  .toLowerCase();

 const args = message.content
  .slice(prefix.length)
  .split(' ')
  .slice(1);

 if (command === 'slowmode') {
  if (!message.member.hasPermission('MANAGE_CHANNELS'))
   return message.channel.send("You don't have access to this command!");

  // Checks if `args[0]` doesn't exist or isn't a number.
  if (!args[0])
   return message.channel.send('You did not specify a correct amount of time!');
  if (isNaN(args[0])) return message.channel.send('That is not a number!');

  // Check if `args[0]` is a correct amount of time to set slowmode
  // Array `validNumbers` are an array consistent of numbers of time you can set slowmode with.
  const validNumbers = [
   5,10,15,30,60,120,300,600,900,1800,3600,7200,21600,];

  // Check if `args[0]` parsed into an interger is included in `validNumbers`
  if (!validNumbers.includes(parseInt(args[0])))
   return message.channel.send('Invalid Number! Number must be below 21600.');

  // Set the slowmode
  message.channel.setRateLimitPerUser(args[0]);

  // Send the reply
  message.channel.send(`Slowmode Set to **${args[0]}**`);
 }
});

client.login('');

但是我得到如下错误

SELECT * FROM lighting WHERE cast("time" as timestamp) BETWEEN '23:55:00'::timestamp AND Now();

我的“时间”列以文本格式如下

ERROR:  column "23:55:00::timestamp" does not exist LINE 3: WHERE  cast("time" as timestamp) BETWEEN "23:55:00::timestam...

我在做什么错了?

解决方法

似乎您的“时间”字段的值为time,无法转换为timestamp

所以尝试这种方式:

SELECT *
FROM   lighting
WHERE  cast("time" as time) BETWEEN '23:55:00'::time
AND current_time;