Your problem here is quoting. You need to escape the quotes around the
SQL strings so that the shell (I assume you're using Unix of some
flavour) doesn't interpret them:
/usr/local/pgsql/bin/psql -d temp -c 'insert into
temp.ip_mapping_tb(ip,location) values(\'192.100.9.51\',\'FirstFloor\')'
However, if I were you I would consider running via a file anyway - if
you save your query into a file then you can use
psql -d temp -f foo.sql
instead. Within the file you can type your query exactly like it should
be with no special escaping required.
Hope this helps,
Robin
dhanesh.prabha@xxxxxxxxx wrote:
Hi ,
I am trying to insert data into the table via shell script using
psql command.
But it giving syntax error. the same query is finely working pgAdmin
III client.
The query and error given below.
Eg:
ERROR: syntax error at or near ".9" at character 85
LINE 1: ...pping_tb(ip,location) values(192.100.9.51,Firs...
Also when i am givinf Firstfloor as First Floor it was giving
error
/usr/local/pgsql/bin/psql -d temp -c 'insert into
temp.ip_mapping_tb(ip,location) values('192.100.9.51','First Floor')'
psql: FATAL: role "Floor)" does not exist