linux - psql return code if zero rows found -
i psql command fail if 0 rows found:
psql -u postgres -d db -c "select * user id=1 , name='joe';"
i want able check return value. return 0 process(!) if @ least 1 row exists , return non-zero psql process if no such row exists. how can set return code if no rows found?
i don't think psql can itself, if want see if there rows or not exit status combine like
psql -u postgres -d db -t -c "select * user id=1 , name='joe'" | egrep .
that cause egrep exit non-zero if cannot match anything. -t
make not print column headers , summary information, may need tweak command line if need stuff.
Comments
Post a Comment