Re: SQL Query Syntax help

2020-01-22 Thread David G. Johnston
On Wednesday, January 22, 2020, srikkanth wrote: > Hi Jan, > > Thanks for your input, it is working exactly what i want, but still i m > facing issue because in my table there are different data types they are 10 > to 15 columns are Boolean, one primary key, 140 columns are character. > > when i

Re: SQL Query Syntax help

2020-01-22 Thread srikkanth
in this case.Thanks,Srikanth BFrom: Jan Kohnert <nospam001-li...@jan-kohnert.de>Sent: Wed, 22 Jan 2020 17:11:56To: pgsql-general@lists.postgresql.orgSubject: Re: SQL Query Syntax helpHi,Am Mittwoch, 22. Januar 2020, 12:00:45 CET schrieb srikkanth:[sniped HTML]something likeselect   id, 'Co

Re: SQL Query Syntax help

2020-01-22 Thread Geoff Winkless
On Wed, 22 Jan 2020 at 11:00, srikkanth wrote: > Can you please help me in writing the syntax for the below mentioned table. > Suggest looking at the crosstab function. https://www.postgresql.org/docs/current/tablefunc.html crosstab(text source_sql, text category_sql) Produces a "pivot

Re: SQL Query Syntax help

2020-01-22 Thread Daniel Verite
srikkanth wrote: > Can you please help me in writing the syntax for the below mentioned This looks like an UNPIVOT operation. Here's a generic method that does this without having to specify the columns individually, with the help of json functions: SELECT ID, key, value FROM (SELECT

Re: SQL Query Syntax help

2020-01-22 Thread Jan Kohnert
Hi, Am Mittwoch, 22. Januar 2020, 12:00:45 CET schrieb srikkanth: [sniped HTML] something like select id, 'Col A' as "Col Name", "Col A" as "Col Value" from input union all select id, 'Col B' as "Col Name", "Col B" as "Col Value" from input ... order by 1, 2; should work. -- Kin

Re: sql query for postgres replication check

2019-11-24 Thread Michael Paquier
On Fri, Nov 22, 2019 at 01:20:59PM +, Zwettler Markus (OIZ) wrote: > I came up with the following query which should return any apply lag in > seconds. > > select coalesce(replay_delay, 0) replication_delay_in_sec > from ( >select datname, > ( > select ca

Re: SQL query

2019-04-18 Thread Ravi Krishna
> The above is not the same format as OP's query: > > Update tableA set col1 = null and col2 in (1,2); I did include set in the sql. I typed it wrong here.

Re: SQL query

2019-04-18 Thread Adrian Klaver
On 4/18/19 11:36 AM, Ravi Krishna wrote: Not able to produce this with PG 11.1 If col1 is any type other than boolean, the update statement fails in syntax. If col1 is boolean, then it updated it correctly. In other words update col1 = NULL and col2 in (1,2) is treated same as upda

Re: SQL query

2019-04-18 Thread Ravi Krishna
"Ravi Krishna" > To: "Vikas Sharma" > Cc: pgsql-general@lists.postgresql.org > Subject: Re: SQL query > > Not able to produce this with PG 11.1 > > If col1 is any type other than boolean, the update statement fails in syntax. > If col1 is bool

Re: SQL query

2019-04-18 Thread Ravi Krishna
Not able to produce this with PG 11.1 If col1 is any type other than boolean, the update statement fails in syntax. If col1 is boolean, then it updated it correctly. In other words update col1 = NULL and col2 in (1,2) is treated same as update col1 = NULL where col2 in (1,2) Also

Re: SQL query

2019-04-18 Thread Ron
On 4/18/19 11:43 AM, Vikas Sharma wrote: Hi, I have come across a query that a developer wrote to update a few rows in table, the query did update the two desired rows but also updated the rest of the table with the column value as 'false'. Update tableA set col1 = null and col2 in (1,2); T

Re: SQL query

2019-04-18 Thread Adrian Klaver
On 4/18/19 9:43 AM, Vikas Sharma wrote: Hi, I have come across a query that a developer wrote to update a few rows in table, the query did update the two desired rows but also updated the rest of the table with the column value as 'false'. Update tableA set col1 = null and col2 in (1,2); Th

Re: SQL Query never ending...

2018-06-22 Thread DiasCosta
Hello Tom, good evening. Thank you for your prompt answer and help. It was enough to ANALYZE the temp tables to achieve a magnificent result:  37 seconds. I'm portuguese. It's a shame you live so far from me. So I can't put a box of bottles of Porto wine at your door. I also thank David an

Re: SQL Query never ending...

2018-06-21 Thread Tom Lane
DiasCosta writes: > This is the query plan for only 19684 rows. I think you're getting a bad query plan, mostly as a result of two factors: * Poor row estimates. It looks like the bottom-most misestimations are on temp tables, which makes me wonder whether you've ANALYZEd those tables. Your ap

Re: SQL Query never ending...

2018-06-21 Thread DiasCosta
Hello David and Fabrízio, The names of the tables and indexes differ from the original script. Only the names. This is the query plan for only 19684 rows. I have another query running for around 3 rows, but it takes an eternity to finish. If it finishes in acceptable time I'll make it a

Re: SQL Query never ending...

2018-06-20 Thread David G. Johnston
On Wed, Jun 20, 2018 at 3:34 PM, Fabrízio de Royes Mello < fabri...@timbira.com.br> wrote: > And use some external service like pastebin.com to send long SQL > statements. > ​Or just attach a text file - those are allowed on these lists. ​ David J.

Re: SQL Query never ending...

2018-06-20 Thread Fabrízio de Royes Mello
2018-06-20 18:35 GMT-03:00 DiasCosta : > > Hi all, > can someone help me? > > I don't know if this is the correct list for this matter. If I'm wrong, please bear with me and point me in right direction. > Here is a good start... > I have a large query which, largely after more than 24 hours run