Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psql:ERROR: syntax error at or near "" LINE 1:  [duplicate]

Hi I have written this script to execute pgSQL function and I'm getting this error

#!/bin/bash

cd /home/NorthStar/Dhruva/server-specific-scripts/crons/ResetETA

db="Dhruva"
file="/home/NorthStar/Dhruva/server-specific-scripts/crons/ResetETA/query.sql"

cmd="psql -d $db -f $file"

su postgres -c "$cmd" >> reset.log 2> reset.log

if su postgres -c "$cmd"; then
    echo "ETA Reset successed" >> resset.log
else
    echo "ETA Reset faild" >> reset_error.log
fi
like image 651
raj verma Avatar asked Sep 15 '25 20:09

raj verma


1 Answers

Looks like a Unicode byte-order mark.

Use a text editor that saves plain utf-8 text without a byte-order mark, like notepad++, Sublime Text, gedit, vim/emacs, etc to write your scripts.

Don't write SQL, or any other programming-style code, with a word processor.

like image 192
Craig Ringer Avatar answered Sep 18 '25 16:09

Craig Ringer