Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5932237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:48:23+00:00 2026-05-22T14:48:23+00:00

I have the following script, which connects through ssh to a remote server and

  • 0

I have the following script, which connects through ssh to a remote server and issues an SQL statement on it’s Postgresql database:

#!/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"
}

Now I’m trying to issue SELECT and INSERT statements to the following table:

CREATE TABLE pb_properties
(
  c_name character varying(255) NOT NULL,
  c_value character varying(255),
  CONSTRAINT pb_properties_pkey PRIMARY KEY (c_name)
)

This function works fine if I do a SELECT statement:

#!/bin/bash
source db_query.sh
db_query staging "SELECT * FROM pb_properties;"

>> Output: DB_QUERY: rows_count =  support-email | test@test.com

But it does not work if I do an INSERT statement:

#!/bin/bash
source db_query.sh
db_query prestaging "INSERT INTO pb_properties (c_name, c_value) VALUES ('support-email', 'test@test.com');"

>> Output:
>>ERROR:  column "testname" does not exist
>>LINE 1: ...SERT INTO pb_properties (c_name, c_value) VALUES (testname, ...
                                                             ^
>>DB_QUERY: rows_count =

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 ‘.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:48:24+00:00Added an answer on May 22, 2026 at 2:48 pm

    Ok, since I cannot get the SQL statement with single quotes working at all with the db_query method in my question, I’m doing a workaround. On the remote Server, I’m redirecting the SQL statement into a temporary file. Then I can let psql read that file, then I don’t have to care about quotes anymore.

    This is my new db_query function:

    tmpfile=/tmp/pgquery
    
    db_query() {
        app_server="$1"
        sql_stmt="$2"
        ssh $app_server "echo \"$sql_stmt\" > $tmpfile"
        psql_cmd="psql -d vdc --pset tuples_only -f $tmpfile"
        rows_count=`ssh $app_server "sudo su - postgres -c \"${psql_cmd}\""`
    
        echo "DB_QUERY: rows_count = $rows_count"
    }
    

    This now works with my initial statement:

    db_query prestaging "INSERT INTO pb_properties (c_name, c_value) VALUES ('testname', 'testvalue');"
    

    Anyway, if anybody has an hint how to get it working without a temporary file, I’d be glad to hear it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script which I am running. It loops through each table
I have the following script which first shows only the first para of the
I have the following script which appears multiple times on my page. I have
I have the following script, which is working for the most part Link to
I have a problem with following script. It generates a list of places which
I have an image uploading script in which i use the following setup to
I have a CSV export script (enrdata_arch.php) which calls information from an existing database
I have the following script which works perfectly until I regenerate the links .resultLink
I have the following script which works kind of... $(document).ready(function(){ // add or remove
I have the following script to create a table in MySQL version 5.1 which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.