Re: Postgresql 9.5 and Shell scripts/variables vs. C programming/defining a value to be used - Mailing list pgsql-general

From Poul Kristensen
Subject Re: Postgresql 9.5 and Shell scripts/variables vs. C programming/defining a value to be used
Date
Msg-id CAAOuvVqLb4YNexhHRXesa=G5vdA3oBhHRLp4S0NSyGppwCnFNg@mail.gmail.com
Whole thread Raw
In response to Re: Postgresql 9.5 and Shell scripts/variables vs. C programming/defining a value to be used  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Postgresql 9.5 and Shell scripts/variables vs. C programming/defining a value to be used  (Poul Kristensen <bcc5226@gmail.com>)
List pgsql-general
My goal is to grap a user from the OS and and substitute the grapped user - to be the owner of the database - in the sql commands
e.g using shell-script substitution syntax: 
       create user ${user} with login; 
       create tablespace ${user} location '/path/${user)'; 
       create database ${user} owner ${user} on tablespace ${user};
I would be surpriced if this should not be possible using gnu gcc but I might be wrong. It is just a question of figurering out way to do this. 
http://zetcode.com/db/postgresqlc/ has an example of how to do this using integer as argument on 
the commandline.
Do you have a hint of the substitution syntax to be used in gnu gcc.

Thanks.

/Poul



2016-11-23 16:44 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Wed, Nov 23, 2016 at 3:46 AM, Poul Kristensen <bcc5226@gmail.com> wrote:
>> In the postgresql.log I get "select datname from $1".

> ​That is expected when you parameterize a query - the query string includes
> parameter​s instead of values.

It looks like Poul is hoping to use a parameter as a table name,
which doesn't work.  Parameters can only represent values (constants).

                        regards, tom lane



--
Med venlig hilsen / Best regards
Poul Kristensen
Linux-OS/Virtualizationexpert and Oracle DBA

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Partial update on an postgres upsert violates constraint
Next
From: Kevin Grittner
Date:
Subject: Re: Methods to quiesce PostgreSQL DB without configuring log archival