I got a script database that looks for duplicate identifiers when it is assigned a specific identifier, last name and first name. Here are the meat and potatoes:
PSQL="psql -p $PGPORT -h $DBHOST -d $DB -tAc "
DUP_ID=$($PSQL "SELECT id FROM inmate WHERE id NOT SIMILAR TO '(0*)${1}' AND lastname ILIKE '${_LNAME}' AND firstname ILIKE '${_FNAME}' LIMIT 1")
It works fine, unless the last or first name has an apostrophe in it, for example, "O'Neil". I tried to escape from any instance of "c" and have not yet succeeded. I searched the forums all day and tried different options myself, but he still wonβt add \ before each.
Here is what I got so far:
local _LNAME=`echo "${2}" | sed "s/'/\\\'/g"`
local _FNAME=`echo "${3}" | sed "s/'/\\\'/g"`
echo -e $_LNAME
echo -e $_FNAME
O'Neil
Robert
As always, thanks in advance!
source
share