Note that there are some explanatory texts on larger screens.

plurals
  1. POPostgres command line statement: INSERT complains about non-existing column
    text
    copied!<p>I have the following script, which connects through ssh to a remote server and issues an SQL statement on it's Postgresql database:</p> <pre><code>#!/bin/bash db_query() { app_server="$1" sql_stmt="$2" psql_cmd="psql -d vdc --pset tuples_only -c '$sql_stmt'" rows_count=`ssh $app_server "sudo su - postgres -c \"$psql_cmd\""` echo "DB_QUERY: rows_count = $rows_count" } </code></pre> <p>Now I'm trying to issue SELECT and INSERT statements to the following table:</p> <pre><code>CREATE TABLE pb_properties ( c_name character varying(255) NOT NULL, c_value character varying(255), CONSTRAINT pb_properties_pkey PRIMARY KEY (c_name) ) </code></pre> <p>This function works fine if I do a SELECT statement:</p> <pre><code>#!/bin/bash source db_query.sh db_query staging "SELECT * FROM pb_properties;" &gt;&gt; Output: DB_QUERY: rows_count = support-email | test@test.com </code></pre> <p>But it does not work if I do an INSERT statement:</p> <pre><code>#!/bin/bash source db_query.sh db_query prestaging "INSERT INTO pb_properties (c_name, c_value) VALUES ('support-email', 'test@test.com');" &gt;&gt; Output: &gt;&gt;ERROR: column "testname" does not exist &gt;&gt;LINE 1: ...SERT INTO pb_properties (c_name, c_value) VALUES (testname, ... ^ &gt;&gt;DB_QUERY: rows_count = </code></pre> <p>Now how can I do a successful INSERT statement with my db_query function? I already tried masking the values I tried to insert in many several ways, but none of them worked. I guess it has something to do with the combination of running the sql command through SSH and the different quotes i'm using `, " and '.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload