Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 将循环内psql查询的单个数据打印到stoud_Bash_Postgresql_Loops_Stdout_Psql - Fatal编程技术网

Bash 将循环内psql查询的单个数据打印到stoud

Bash 将循环内psql查询的单个数据打印到stoud,bash,postgresql,loops,stdout,psql,Bash,Postgresql,Loops,Stdout,Psql,我有一个逗号分隔的csv文件。将其简化如下所示: uuid,other_data # this one is not presented, just the data uuid1,other_data1 uuid2,other_data2 ... uuidN,other_dataN #!/bin/bash while IFS=, read uuid other_data do psql -h <host> -p <port> -U <user> &l

我有一个逗号分隔的csv文件。将其简化如下所示:

uuid,other_data # this one is not presented, just the data
uuid1,other_data1
uuid2,other_data2
...
uuidN,other_dataN
#!/bin/bash
while IFS=, read uuid other_data
do
    psql -h <host> -p <port> -U <user> <database> -c "select some_column from some_table where uuid='$uuid'"
done < $1
我在bash脚本中循环它,如下所示:

#!/bin/bash
while IFS=, read uuid other_data
do
    echo $uuid
done < $1
  some_column  
---------------
 8410043071264
(1 row)

  some_column  
---------------
 8410069001030
(1 row)
。。。将导致如下结果:

#!/bin/bash
while IFS=, read uuid other_data
do
    echo $uuid
done < $1
  some_column  
---------------
 8410043071264
(1 row)

  some_column  
---------------
 8410069001030
(1 row)

如何仅获取值?(8410043071264, 8410069001030). 我能把它加载到一个变量中,在循环中处理它吗?这是行不通的,但您得到了这样的想法:在循环中
some_column=$(psql-h-p-U-c“从某个_表中选择某个_列,其中uuid='$uuid')
,然后
echo$some_column

您可以尝试下面的-t选项吗

psql -h <host> -p <port> -U <user> <database> -t -c "select some_column from some_table where uuid='$uuid'"
psql-h-p-U-t-c“从uuid='$uuid'的某个_表中选择某个_列”
仅元组(无页眉/页脚):-t


psql的精美手册中说:
-t关闭列名和结果行计数页脚等的打印。这相当于\t命令。
非常好的一点,谢谢,正如@Ctx建议的那样。甚至
some_column=$(psql-h-p-U-t-c“从uuid='$uuid'”的某个表中选择某个_列)
也可以正常工作。谢谢