I have this function in postgresSQL and I need some help to take them from enviroment. Adding Vars in DockerFile CREATE OR REPLACE FUNCTION prc_get_connstr() RETURNS TEXT AS $$ DECLARE   res TEXT;   SRC_ADDR varchar(50) := `echo ${SRC_ADDR_CRD:-noaddr}`;   SRC_PORT varchar(50) := `echo ${SRC_PORT_CDR:-noport}`;   SRC_DB varchar(50) := `echo ${SRC_DB_CDR:-nodb}`;   SRC_USR varchar(50) := `echo ${SRC_USR_CDR:-nouser}`;   SRC_PASS varchar(50) := `echo ${SRC_PASS_CDR:-nopass}`; BEGIN   RETURN 'dbname=SRC_DB host=SRC_ADDR port=SRC_PORT user=SRC_USR password=SRC_PASS connect_timeout=5'; END; $$ LANGUAGE 'plpgsql';  When I deploy it doesn't work You are now connected to database &quot;cdr&quot; as user &quot;postgres&quot;. CREATE EXTENSION CREATE FUNCTION psql:/docker-entrypoint-initdb.d/2_cdr_trigger.sql:31: ERROR:  syntax error at or near &quot;$&quot; LINE 6:   SRC_ADDR varchar(50) := `echo ${SRC_ADDR_CRD:-noaddr}`;  What i have to do to declare de enviroment vars.
68349
In MS SQL Server, I create my scripts to use customizable variables:  DECLARE @somevariable int   SELECT @somevariable = -1  INSERT INTO foo VALUES ( @somevariable )   I'll then change the value of @somevariable at runtime, depending on the value that I want in the particular situation. Since it's at the top of the script it's easy to see and remember.  How do I do the same with the PostgreSQL client psql?
88155
I have PostgreSQL CSV-log its &quot;errors&quot; according to this structure:  It doesn't include the file path to the script which ran the query, so I have no idea where it occurred besides the vague, essentially useless hint from the &quot;application_name&quot;. How do I make it log which file caused the error/warning/log? My first thought was to just add my own column to the table, called file_path, but then I realized that this won't help, since my script which does the COPYing of the csvlog data into my table has no idea from where the entries origin, since they are not logged by PostgreSQL. Without knowing where the error occurs, I might as well not have a log at all. How do I make it log the file path and not just the application_name? I'm baffled as to why this is lacking in the table structure/CSVlog dump format. The &quot;detail&quot; column is almost always empty, so there are no file paths there for me to extract.
121769
I am using this  to convert a GeoJSON point from EPSG:3857 to EPSG:4326.   My command fails. What am I doing wrong?   $ echo '{"type":"Point","coordinates":[-13720479.997764934,5688254.733325758]}' | reproject --from=EPSG:3857 --to=EPSG:4326   /usr/local/lib/node_modules/reproject/cli.js:98             throw new Error("Could not find definition for CRS \"" + crsName + "\".");                   ^ Error: Could not find definition for CRS "EPSG:3857".     at lookupCrs (/usr/local/lib/node_modules/reproject/cli.js:98:10)     at Object.&lt;anonymous&gt; (/usr/local/lib/node_modules/reproject/cli.js:25:1)     at Module._compile (module.js:456:26)     at Object.Module._extensions..js (module.js:474:10)     at Module.load (module.js:356:32)     at Function.Module._load (module.js:312:12)     at Function.Module.runMain (module.js:497:10)     at startup (node.js:119:16)     at node.js:901:3
95913
How can I get Environnment variables and if something is missing, set the value?
7196
Is there an easy way to run a MySQL query from the Linux command line and output the results in  format?  Here's what I'm doing now:  mysql -u uid -ppwd -D dbname &lt;&lt; EOQ | sed -e 's/        /,/g' | tee list.csv select id, concat("\"",name,"\"") as name from students EOQ   It gets messy when there are a lot of columns that need to be surrounded by quotes, or if there are quotes in the results that need to be escaped.
52772
I know how to map a list to a string:  foostring = ",".join( map(str, list_of_ids) )   And I know that I can use the following to get that string into an IN clause:  cursor.execute("DELETE FROM foo.bar WHERE baz IN ('%s')" % (foostring))   What I need is to accomplish the same thing SAFELY (avoiding SQL injection) using MySQLDB. In the above example because foostring is not passed as an argument to execute, it is vulnerable. I also have to quote and escape outside of the mysql library.   (There is a , but the answers listed there either do not work for MySQLDB or are vulnerable to SQL injection.)
8186
is there an alternative for mysql_insert_id() php function for PostgreSQL? Most of the frameworks are solving the problem partially by finding the current value of the sequence used in the ID. However, there are times that the primary key is not a serial column....
89206
I am getting error:     The argument 2 of the "JSON_VALUE or JSON_QUERY" must be a string literal   ...while trying to pass variable as parameter to JSON_QUERY function. Please help me to resolve it.  DECLARE @cnt INT = 1; DECLARE @cnt_total INT = 1; DECLARE @json NVARCHAR(MAX); DECLARE @json1 NVARCHAR(MAX); declare @str  VARCHAR(200);  WHILE @cnt &lt;= 10 BEGIN     set @str = '$.Seasons[0].Products['+convert(varchar,@cnt)+'].ProductChannels';     set @str = char(39) +@str+ char(39);     PRINT @STR     select @json = json_query(jfile,@STR) from Import.tstjson; --MORE CODE         SET @cnt = @cnt + 1; END   Sample data:  {   "Seasons": [     {       "Season": "12321231",       "Products": [         {           "ProductId": "211",           "ProductChannels": [             {               "ChannelId": 1,               "WeekQuantities": []             }           ],           "ccc": 3,           "Tttt": 4         }       ]     }   ] }
59875
The question says it all. I currently use Arch Linux and the zsh, but I'd like a solution that (at minimum) works both on VTs and in xterms and also (hopefully, preferably) will continue to work if I switch distros or shells.  I've heard wildly disparate answers to this question in different distros' docs. Ubuntu says "use .pam_environment". I think in Arch what they recommend depends on your shell. Currently I put everything in  and if a shell doesn't source that for some reason (e.g. bash if .bash_profile exists), I override that by manually sourcing it. But it seems like there must be a better way.
55687
Given I have in a bash script  ev=USER   How can I get the environment variable value for $USER using ev?  Tried naively doing:  echo ${"$"$ev}   which results in bad substitution.  I'd expect to get back whatever the value of $USER is.
43199
I am having basic problems using PostgreSQL on my Mac OSX Yosemite, through the terminal. I tried google-ing but this is becoming increasingly difficult and info very scattered so I keep running into walls. I did the following:  installed PostgreSQL 9.5.2 via Homebrew modified my shell config file (.zshrc) to include PostgreSQL bin directory in $PATH variable I did the &quot;initdb&quot; routine and &quot;told&quot; Postgres that I want to store my databases in /usr/local/cellar/postgresql/9.5.2/data  Here I tried starting postgreSQL: $pg_ctl /usr/local/cellar/postgresql/9.5.2/data -l logfile start  first error:  pg_ctl: another server might be running; trying to start server anyway /bin/sh: logfile: Permission denied  As far as I understand, I am trying to start the PostgreSQL server and direct its output and errors into a log file, located in a location for which my user has no write privileges. How can I fix this? Here I tried stopping the server and try again: $pg_ctl -D /usr/local/cellar/postgresql/9.5.2/data stop   This worked ok. So,  How can I use other location to start the server and enable log How do I check if the server is running if I need to stop it (if errors appear)?
100441
We completed development on our dev environment and I copied the files over from the dev server to the production server through FTP.   Then through back up and migrade module, I made a back up of the SQL database. I created a new database through Plesk with the same name, username and password. I then imported the SQL database into the new server through phpmyadmin. I go to the URL and get the Site Maintenance message (which is correct, I placed the site in maintenance mode before copying the files over) but cannot navigate to any sub pages. Generally I can add /user or /admin to the end of the url and get the login screen. However all I get are 404 errors.
90468
I have postgresql 8.4 installed on my desktop. It keeps starting on bootup because I think I used default settings.   so I issue /etc/init.d/postgresql stop everytime and sometimes i keep forgetting  It has folder paths as,  /etc/postgresql/8.4/main /usr/lib/postgresql/8.4   There are a lot of configuration files and if someone can tell me where to look and what to change, that will be great.   Thanks.
124237
I want to  GRANT SELECT     ON ALL TABLES     TO foo;   But postgres tells me I have a syntax error at "TO". It expects a GRANT like:  GRANT SELECT     ON ALL TABLES     IN SCHEMA public     TO foo;   We have a handful of tables that have been sharded such that public, shard123, and shard124 all have a table my_table, and public.my_table is the parent of both shard123.my_table and shard124.my_table. I've GRANTed SELECT to foo for public schema, but foo doesn't have permission for any of the shard schemas.  I've also done:  ALTER DEFAULT PRIVILEGES     FOR ROLE dba     GRANT SELECT     ON TABLES     TO foo;   ...which should automatically grant for any new tables and schemas made from now on.  There are 1000 &lt; n &lt; 10000 shards/schemas, so GRANTing separately for each shard/schema is impractical.  How can I GRANT to a role for all existing tables across all existing schemas (all shards)?  Or even better, can I GRANT for all schemas LIKE 'shard%'?
101212
I'm trying to establish a Postgres connection using QgsCredentials as described here:    The only problem is that I cannot establish a working connection unless I "physically" add the layer to the map canvas (which I don't want because I only want a connection to the DB and a reference to the layer which will be edited later on in the code)  When clicking a button the run function reads:  uri = QgsDataSourceURI() connInfo = uri.connectionInfo()  (success, user, passwd) = QgsCredentials.instance().get(connInfo, None, None)  if success:     # Isn't this enough to establish the connection and get a valid reference to the layer?     uri.setConnection("HOST", "PORT", "DB_NAME", user, passwd)     uri.setDataSource("SCHEMA", "TABLE_NAME", "the_geom")     LYR = QgsVectorLayer(uri.uri(), "LYR", "postgres")      # Unless I add the following line, I am not able to use properly the object     # (which asks the user the credentials until he/she inserts the right ones and gets     # a working connection with a valid reference to the layer)     QgsMapLayerRegistry.instance().addMapLayer(LYR)   What am I doing wrong?  Thanks in advance,  m.
71133
I'd like to insert an input variable (integer) in a query SQL (@variable) using the algorithm postgresql execute sql in the graphical modeler of QGIS. For example, in this kind of query INSERT INTO table2 SELECT * FROM table1 WHERE ID = @variable;  where I should insert the variable in the input panel of the modeler and click play to do the query. I used pre-calculated value but with no success. Any suggestion?
66399
I have the following code:  const string Sql =      @"select distinct [name]        from tblCustomers        left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId         where (tblCustomer.Name LIKE '%@SEARCH%' OR tblCustomerInfo.Info LIKE '%@SEARCH%');";  using (var command = new SqlCommand(Sql, Connection)) {            command.Parameters.AddWithValue("@SEARCH", searchString);     ... }   This does not work, I tried this as well:  const string Sql =      @"select distinct [name]       from tblCustomers       left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId        where (tblCustomer.Name LIKE @SEARCH OR tblCustomerInfo.Info LIKE @SEARCH );";  using (var command = new SqlCommand(Sql, Connection)) {            command.Parameters.AddWithValue("@SEARCH", "'%" + searchString + "%'");     ... }   but this does not work as well. What is going wrong? Any suggestions?