Re: nth_value out of more than n values returns null

2024-11-04 Thread Tom Lane
"David G. Johnston" writes: > So just use “offset 5_000_000 limit 1”. Bringing in a window function here > seems unhelpful. Yeah, that. A bite-size example might help clarify what the window function is doing: regression=# create table zed(f1 int) ; CREATE TABLE regression=# insert into zed se

Re: nth_value out of more than n values returns null

2024-11-04 Thread David G. Johnston
On Monday, November 4, 2024, Guyren Howe wrote: > I’m trying to get the id of the 5,000,000th record, so I can join against > it to get a name. I didn’t fully understand what the docs say there. What > am I missing? > So just use “offset 5_000_000 limit 1”. Bringing in a window function here se

Re: nth_value out of more than n values returns null

2024-11-04 Thread David G. Johnston
On Monday, November 4, 2024, Guyren Howe wrote: > Wouldn’t it be offset 4_999_999? > Probably. I tend to expect off-by-one for these kinds of things and test my way out. > > I’d still like to understand why nth_value doesn’t work. > When you perform an order by in a window clause the frame y

Re: nth_value out of more than n values returns null

2024-11-04 Thread Guyren Howe
Wouldn’t it be offset 4_999_999? I’d still like to understand why nth_value doesn’t work. On 4 Nov 2024 at 15:44 -0800, David G. Johnston , wrote: > On Monday, November 4, 2024, Guyren Howe wrote: > > I’m trying to get the id of the 5,000,000th record, so I can join against > > it to get a name

Re: nth_value out of more than n values returns null

2024-11-04 Thread Guyren Howe
I’m trying to get the id of the 5,000,000th record, so I can join against it to get a name. I didn’t fully understand what the docs say there. What am I missing? On 4 Nov 2024 at 15:36 -0800, Erik Wienhold , wrote: > On 2024-11-05 00:17 +0100, Guyren Howe wrote: > > This query: > > > > SELECT NTH

Re: nth_value out of more than n values returns null

2024-11-04 Thread Erik Wienhold
On 2024-11-05 00:17 +0100, Guyren Howe wrote: > This query: > > SELECT NTH_VALUE(id, 500) OVER (ORDER BY created_at, id ASC) FROM table > > in a table where SELECT COUNT(*) returns a value a few thousand over 5 > million, where id is the primary key, returns null. > > The inclusion of the pr

Re: nth_value out of more than n values returns null

2024-11-04 Thread Adrian Klaver
On 11/4/24 15:17, Guyren Howe wrote: This query: SELECT NTH_VALUE(id, 500) OVER (ORDER BY created_at, id ASC) FROM table in a table where SELECT COUNT(*) returns a value a few thousand over 5 million, where id is the primary key, returns null. The inclusion of the primary key should make

nth_value out of more than n values returns null

2024-11-04 Thread Guyren Howe
This query: SELECT NTH_VALUE(id, 500) OVER (ORDER BY created_at, id ASC) FROM table in a table where SELECT COUNT(*) returns a value a few thousand over 5 million, where id is the primary key, returns null. The inclusion of the primary key should make the order by a total order. So there s

Re: Used memory calculation in containers - docker stats and file cache

2024-11-04 Thread Peter J. Holzer
On 2024-11-04 14:35:23 +0100, Costa Alexoglou wrote: > > I don't know if Docker does anything strange here. > > I am not sure if this is docker specific or cgroup comes into play.  > The measurement is implemented in docker CLI, but I would make the > assumption that the eviction is done within th

Re: Column name beginning with underscore ("_")?

2024-11-04 Thread Adrian Klaver
On 11/4/24 12:02, Jim Rosenberg wrote: Is it considered bad Postgresql practice to have a column name that begins with the underscore character ("_")? I'm not sure where this is documented, but I'm seeing that Postgresql accepts prepending an underscore to a data type name as a kind of alias for

Re: Column name beginning with underscore ("_")?

2024-11-04 Thread Tom Lane
Jim Rosenberg writes: > Is it considered bad Postgresql practice to have a column name that begins > with the underscore character ("_")? I wouldn't say so. > I'm not sure where this is documented, but I'm seeing that Postgresql > accepts prepending an underscore to a data type name as a kind of

Column name beginning with underscore ("_")?

2024-11-04 Thread Jim Rosenberg
Is it considered bad Postgresql practice to have a column name that begins with the underscore character ("_")? I'm not sure where this is documented, but I'm seeing that Postgresql accepts prepending an underscore to a data type name as a kind of alias for appending [] to define an array data typ

Re: Why not do distinct before SetOp

2024-11-04 Thread Tom Lane
David Rowley writes: > On Mon, 4 Nov 2024 at 22:52, ma lz wrote: >> select distinct a from t1 intersect select distinct a from t1;— this is >> faster than origin sql > No, the planner does not attempt that optimisation. INTERSECT really > isn't very well optimised. It's not really obvious

Re: Used memory calculation in containers - docker stats and file cache

2024-11-04 Thread Costa Alexoglou
> I don't know if Docker does anything strange here. I am not sure if this is docker specific or cgroup comes into play. The measurement is implemented in docker CLI, but I would make the assumption that the eviction is done within the cgroup scope. > A large file (or many smaller files) which is

Re: Why not do distinct before SetOp

2024-11-04 Thread David Rowley
On Mon, 4 Nov 2024 at 22:52, ma lz wrote: > > some sql like ' select a from t1 intersect select a from t1 ' > > if t1 has large number rows but has few distinct rows > > select distinct a from t1 intersect select distinct a from t1;— this is > faster than origin sql > > can postgres do this o

Why not do distinct before SetOp

2024-11-04 Thread ma lz
some sql like ' select a from t1 intersect select a from t1 ' if t1 has large number rows but has few distinct rows select distinct a from t1 intersect select distinct a from t1;― this is faster than origin sql can postgres do this optimize during plan-queries?