Indexes that would span partitions.

2022-03-13 Thread Tim Uckun
What's a good strategy for dealing with indexes (multiple) that would span multiple partitions of a table. For example: Let's say I have a table that's partitioned by group_id because I want all the records for a group to be in the same partition. Let's say I have a field called "expires_at" whi

Re: delete query using CTE

2022-03-13 Thread benj . dev
Le 13/03/2022 à 15:44, Roger Bos a écrit : Hello, trying to use CTE to remove duplicates from a table.  The DELETE version does not work, but the SELECT version does, so I am not understanding what the problem is.  Any suggestions on how to fix it? Here is my query: WITH cte AS ( SELECT *, RO

Re: delete query using CTE

2022-03-13 Thread Roger Bos
Thank you Michael & David for your extremely fast response. With your help I was able to fix the query as follows: DELETE FROM price_old WHERE ctid IN (SELECT ctid FROM (SELECT ctid, ROW_NUMBER() OVER( PARTITION BY ticker, date ORDER BY ctid ) AS my_row_num

Re: delete query using CTE

2022-03-13 Thread David G. Johnston
On Sun, Mar 13, 2022 at 7:44 AM Roger Bos wrote: > WITH cte AS > ( SELECT *, ROW_NUMBER() OVER ( PARTITION BY ticker, date ORDER BY ticker, > date) my_row_num FROM price_old) > DELETE FROM cte WHERE my_row_num > 1; > > I get the following error: > > ERROR: relation "cte" does not exist LINE 3: DE

Re: delete query using CTE

2022-03-13 Thread Michael Lewis
You can't delete rows that are in a CTE. You want to delete rows that are in the table. Do you have a primary key that you can reference? Else, you may need to reference the system column ctid.

delete query using CTE

2022-03-13 Thread Roger Bos
Hello, trying to use CTE to remove duplicates from a table. The DELETE version does not work, but the SELECT version does, so I am not understanding what the problem is. Any suggestions on how to fix it? Here is my query: WITH cte AS ( SELECT *, ROW_NUMBER() OVER ( PARTITION BY ticker, date ORD

Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines

2022-03-13 Thread Francisco Olarte
Dominique: On Fri, 11 Mar 2022 at 21:13, Dominique Devienne wrote: > But sure, if TEXT does the kind of pseudo-CSV I need, I'd change it to use it. Text, the original format for copy, is much easier to manage than CSV. It can easily be managed as you can split the whole input on newlines to get

Re: COPY TO STDOUT WITH (FORMAT CSV, HEADER), and embedded newlines

2022-03-13 Thread Francisco Olarte
Hi Daniel: On Fri, 11 Mar 2022 at 19:38, Daniel Verite wrote: > > These values are 'normal'. I'm not use to CSV, but I suppose > > such newlines > > must be encoded, perhaps as \n, since AFAIK CSV needs to be 1 line per row, > > no? > No, but such fields must be enclosed by double quotes, as docu