mohpc04pp1: /h/u544835 % psql arco
Welcome to psql 8.1.17, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
WARNING: You are connected t
我需要从bash/expect脚本执行以下sql查询--从bash脚本运行这些查询的首选方法是什么
# psql ambari -U ambari
Password for user ambari:
psql (9.2.24)
Type "help" for help.
ambari=>
ambari=>
ambari=>
ambari=> select
ambari-> sum(case when ulo = 1 then 1 else 0 end) as ulo_1,
ambari-> sum(case when ulo = 2 t
我是新手在bash和psql,我想写一个bash代码,登录服务器的连接到psql数据库做一个选择查询,然后返回输出。我的设置如下。
名为dbs的服务器,它已安装psql并正在运行。数据库名= dname,user=测试仪密码= 1234在数据库中有一个名为node_info的表,表中有3个冒号ip,mac,connection_time。我想运行以下查询select ip,connection_time from node_info where ip=10.10.10.2;
有什么建议吗?如何编写shell脚本来远程完成这项工作?
一直在尝试在结果为空的情况下如何返回消息。
我正在运行select语句,如下所示:
select * from maxIDValue where max_value > 1000000 order by max_value desc;
我是运行在bash脚本通过psql,但结果将发送到一个电子邮件,我有工作。
我想知道的是,如果结果不能返回,那么至少输入一条消息,而不是(0行),即使它只是一条消息,表示没有值或类似的值。
我也尝试过通过bash :注意:.sql文件是上面的查询
{
if [ "$( psql -h $SERVERNAME -U test -d Titan -tA
我在一个外壳脚本中有以下代码,该脚本在docker容器中初始化postgres数据库: if [ "$ENV" == "development" ];
then
psql --username "postgres" --dbname "postgres" <<EOSQL
SELECT 'CREATE DATABASE $DATABASE' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '$DATABASE&
我正在尝试使用远程服务器上的jenkis执行postgres脚本。下面是shell脚本的内容。我使用的是通过SSH发布插件。
sudo -u postgres psql
CREATE USER sonar WITH PASSWORD 'sonar';
\du
CREATE DATABASE sonar WITH OWNER sonar encoding 'UTF8';
GRANT ALL PRIVILEGES ON DATABASE sonar TO sonar;
\l
\q
1)我可以看到在终端中打印了内容,但没有执行。
我尝试过的解决方案:
我创建了如下脚本
我已经在我的MacOS终端上设置了psql。它连接到我通过Amazon RDS运行的PostgreSQL数据库。
我有100个CSV文件(名称1、2、3、4最多100个)。我想批量导入它们。我看到有一些脚本(),但我不知道如何运行脚本。
我试着复制和粘贴这个脚本-
for x in $(ls <folder_name>*.csv);
do psql -c "copy table_name from '$x' csv" also; done
我收到了这些错误-
db=> for x in $(ls <folder_name>*.cs
我目前有一个运行一系列psql脚本的bash脚本。这些psql脚本如下所示:
psql -a -f "filename.sql"
psql -a -f "filename2.sql"
etc.
因此,每个psql都在执行存储在不同文件中的PostgreSQL。我在一个bash脚本中运行了一系列文件,知道每个文件需要多长时间对我很有帮助。
我想到的一种老套的方法是在每次打印之前和之后打印date (即)。
date
psql -a -f "filename.sql"
date
psql -a -f "filename2.sql"
在bash脚本中,我通过'psql -c‘运行sql查询。根据对bash脚本的论证,select命令的where claus将有所不同。所以基本上我需要知道是否有可能做这样的事情:
psql -c "select statement here until we get to the where clause at which point we break out of statement and do"
if (arg1 was given)
concatenate "where arg1" to the end of the above sel