From: | 김명준 <audwns525(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Fwd: Unexpected Multiple Records from Randomized Query |
Date: | 2024-02-22 15:58:51 |
Message-ID: | CAOKhjox_dfmEi5PtxMbAM5sh5W+VA_RO6A8w_jJJx87Cz8g0wQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello. I encountered a problem while setting up a test environment to learn
the use of the random() function.
The query is as follows:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
signup_date DATE
);
INSERT INTO users (name, email, signup_date)
SELECT
'User ' || i,
'user' || i || '@example.com',
NOW() - (random() * (365 * 5) || ' days')::interval
FROM generate_series(1, 1000000) AS s(i);
explain analyze
SELECT * FROM users WHERE name = 'User '||trunc(random()*100) ;
I expected the result to return one record. However, in some cases, the
result comes back with 2 or 3 records. What am I doing wrong?
I'm not sure if this is a conflict issue between the random() and trunc()
functions, or if I have set up the test case incorrectly.
I am using PostgreSQL 15.4 version on Ubuntu 22.04 in a container
environment. PostgreSQL was built by compiling the Source code.
Thank you for your time and consideration.
Best regards,
Myoungjun Kim
From | Date | Subject | |
---|---|---|---|
Next Message | Laurenz Albe | 2024-02-22 16:10:03 | Re: Postgresql assistance needed |
Previous Message | Greg Sabino Mullane | 2024-02-22 14:53:18 | Re: Postgresql assistance needed |