database - postgres脚本遇到语法错误: unexpected end of file

标签 database bash function postgresql

下面我遗漏了一些东西。我总是收到意外的文件结尾。它是什么?

function lock_inactive_accounts {
    echo "Locking inactive accounts or accounts that haven't logged in during the past 35 days."
    echo " "
    echo "The following accounts have been locked: "
    su - postgres -c "psql database" << EOF
      UPDATE users SET has_locked_account = true WHERE DATE_PART('days', now() - last_successful_login) > 35;
      SELECT name from users where has_locked_account = 't';
        EOF
}

lock_inactive_accounts

最佳答案

我相信终止 EOF 应该位于行的开头,此处文档才能正常工作:

su - postgres -c "psql database" <<EOF
  UPDATE users SET has_locked_account = true WHERE DATE_PART('days', now() - last_successful_login) > 35;
  SELECT name from users where has_locked_account = 't';
EOF

关于database - postgres脚本遇到语法错误: unexpected end of file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20691529/

相关文章:

c++ - 是否可以将字符串流作为函数参数传递?

mysql - MySql中存储过程可以调用truncate veiw table并向 View 表输入数据吗

linux - 循环 json 文件/数组 linux bash

bash - 是否可以在使用位置变量时解析 SC2001 ("See if you can use ${variable//search/replace} instead")?

linux - Sed 替换失败,UTF-8 编码

c++ - boolean 函数不起作用

c++ - 用另一个类的 vector 生成类的 vector 的函数声明

database - 删除超过 60 分钟的 Elequent 记录

mysql - SQL数据库架构设计

php - 我如何在我的数据库中配对图像?