I was creating a script to create DB user in Postgres via psql CLI, the challanges I am facing is that value conversion from Any case to lower case is happeing or not able to find the solution for the same. As per my expectation the lowerVal variable should convert the inputValue into lower case value. Did the googles but
Tag: psql
How to write a SQL query which uses the JSON format of table a_json to populate table b with its respective values in postgresql
I have a file named data.json. The structure is like this: { “PrimKey1”: { “layout”: “normal”, “col1”: “PrimKey1”, “__colll2__”: “sometext”, “col3”: 9, “OTHERCOLUMN”:”dontneedthis”, “…
Creating new view psql table by updating duplicate rows in old table
I have a table named t1 and it has 3 columns c1,c2,c3.In t1 there are rows which have duplicate values of c1 but different values of c2 and c3.Now, I wanted to create a psql view table which checks for duplicate c1 and updates the row where it takes the c2 value from the row which has highest value of
Execute sql queries from shell script
I need to execute the following sql queries from bash/expect script what is the preferred approach to run these queries from bash script # psql ambari -U ambari Password for user ambari: psql (9.2.24)…
PostgreSQL, Npgsql returning 42601: syntax error at or near “$1”
While passing PostgreSQL command following error 42601: syntax error at or near “$1” Answer After some testing I found that only table values can be passed as parameter not table name and column name. So I changed code like this
How to search from a table using join?
So I have three tables as follows: Members -> id, userId, accountId Account -> id, name User -> id, firstName, lastName, email INSERT INTO `account` (`id`, `name`) VALUES (‘1’, ‘xyz company’), (‘2’…
How to show leading/trailing whitespace in a PostgreSQL column?
I can’t see leading/trailing whitespace in the following following SQL statement executed with psql: Is there a pragmatic way to see leading/trailing whitespace? Answer If you don’t mind substituting all whitespace characters whether or not they are leading/trailing, something like the following will do it: This is using an underscore to mark the spaces but of course you are free
How to alter a column’s data type in a PostgreSQL table?
Entering the following command into a PostgreSQL interactive terminal results in an error: What is the correct command to alter the data type of a column? Answer See documentation here: http://www.postgresql.org/docs/current/interactive/sql-altertable.html