I have a users table, and I have a stored function get_user_points(int user_id): int. How can I call this procedure for each row in the user's table, then compare the returned value (amount of points) if it is bigger than 100 and if true add user_id to export in the .csv file (if not bigger than 100 just ignore row)?
Add a comment |
2 Answers
Use your function in the WHERE clause and put your query inside COPY
COPY ( SELECT * FROM user_table WHERE get_user_points(int user_id) > 100 ) TO '/path/to/file.csv' - Keep in mind that the file will be created in the database server. If client and server are in different machines you have to stick to
TO STDOUTor to the option provided by @a_horse_with_no_name