What is the easiest way to query from .csv file ?
Ex: I have a list of 1000 email addresses in emails.csv
file.
I want to query all users with emails that are in emails.csv
file
ex:
SELECT *
FROM users
WHERE email IN (emails.csv)
Is there a way to do like this something or I need to create a script. If some script is needed, can you please provide some example.
you need to create a table and copy it from csv, smth like:
t=# create table csv(i int,email text);
CREATE TABLE
t=# copy csv(email) from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself, or an EOF signal.
>> q
>> w
>> \.
COPY 2
t=# select * from csv;
i | email
---+-------
| q
| w
(2 rows)
but In your case you copy from file, not STDIN, eg
copy csv(email) from '/path/to/file';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With