0

I am new to writing raw SQL queries so forgive me for this being easy to solve. The database is Postgres.

I have a table similar to:

taskId     providerName     lastScan     ignore
==================================================
  3        rentCanada        null        false
  4        rentCanada        today       false
  5        rentSeeker        null        false

My goal is to write a query that selects all rows where providerName is rentCanada or rentSeeker and the lastScan value is either null or not null. I wish to count the values for each query.

I tried:

SELECT COUNT(providerName) FROM public."Tasks" HAVING Tasks.providerName=rentSeeker

Gives

ERROR:  column "providername" does not exist
LINE 1: SELECT COUNT(providerName) FROM public."Tasks" HAVING Tasks....
                     ^
HINT:  Perhaps you meant to reference the column "Tasks.providerName".

So I tried to add:

SELECT COUNT("Tasks.providerName") FROM public."Tasks" HAVING Tasks.providerName=rentSeeker

Gives ERROR: column "Tasks.providerName" does not exist LINE 1: SELECT COUNT("Tasks.providerName") FROM public."Tasks" HAVIN...

Ok so maybe without the quotations: SELECT COUNT(Tasks.providerName) FROM public."Tasks" HAVING Tasks.providerName=rentSeeker

Nope, ERROR: missing FROM-clause entry for table "tasks" LINE 1: SELECT COUNT(Tasks.providerName) FROM public."Tasks" HAVING ...

I found PostgreSQL COUNT() function overview and tried: SELECT COUNT(*) FROM public."Tasks" HAVING providerName=rentSeeker

Gives

ERROR:  column "providername" does not exist
LINE 1: SELECT COUNT(*) FROM public."Tasks" HAVING providerName=rent...
                                                   ^
HINT:  Perhaps you meant to reference the column "Tasks.providerName".

I don't understand why so many of the queries I've tried that look like they should work, do not work. As far as I can tell I should be getting results for SELECT * FROM Tasks WHERE lastScan = null but it gives

ERROR:  relation "tasks" does not exist
LINE 1:  SELECT * FROM Tasks WHERE lastScan = null
                       ^

A video I'm watching says SELECT * FROM public.customers WHERE id = 3 so one would think that SELECT * FROM public.Tasks WHERE taskId = 3 would run for me since my table is called Tasks and the id field is called taskId. But no. It doesn't run.

plutownium
  • 1,220
  • 2
  • 9
  • 23
  • 1
    `"providerName"` –  Jan 29 '23 at 17:41
  • `SELECT "providerName" FROM public."Tasks" ` worked! Progress. So did `SELECT "providerName", "lastScan" FROM public."Tasks" WHERE "lastScan" IS NULL`. Thank you! – plutownium Jan 29 '23 at 17:43

0 Answers0