Skip to content

Tag: postgresql

get unique record counts of two joined tables

I have a three tables: topics, sentences, and vocabulary. Sentences and vocabulary both have a belongsTo topic_id, but not all topics necessarily have both vocabulary and sentences. I want to get a count of all topics that have both sentences and vocabulary. I have it working if I do one table at a time: The …

Unable to grant all privileges to new user on Postgres

I’m creating a new user in a Postgres database (AWS RDS) and trying to grant all privileges on all tables in public schema of an existing database to that user. It is failing with below error. I even tried after logging in as the rds_superuser (postgres) and got the same error. psql (13.3, server 10.15)…

Is there any way to join two queries without common columns

Could anyone help me to join two tables without common columns? I have two tables: Tab1 Column1 Column2 K1 a K2 b Tab2 Column1 Column2 K3 c K4 d K5 e The result of select should be: Table1.Column1 Table2.Column1 K1 K3 K1 K4 K1 K5 K2 K3 K2 K4 K2 K5 How do I do that? Answer Fiddle -> https://www.db-fiddle.co…

Why current_date() incurr errors in postgres sql

I have sql like following. But it returned following errors Syntax error at or near Line 19, Position 35 This error was caused by current_date(). How can I avoid this and how can I get current date ? If someone has opinion,please let me know Thanks Answer date_sub() function is only available in Mysql , and c…

SQL total for each row combination

Are there any types of aggregate functions that could help calculate the following? If I have the following data, I want the sum total for each duplicated row. The output would provide total number each row occurs: Answer Why not good old group by and count?

PostgreSQL simply transpose/convert rows to columns

I read some SO posts like sql server 2008 r2 – Transpose rows to columns – Stack Overflow or sql – Postgres – Transpose Rows to Columns – Stack Overflow, but they are too complicated task to what I want to implement, and what I want to is pretty simple task. For example, assume I…