Skip to content
Advertisement

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 output is accurate: Same for

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) ERROR: permission denied for relation

How to query Json field so the keys are the column names and the values are the column fields

PostgreSQL database name is contacts_contact and the column I’m interested in is called “fields” ‘fields’ column looks like this in my database: And a second record: The ‘fields’ column has fields that look like the two JSON data I shared. It is pretty much responses to a survey. Example, {u’Monthly_household_income’: {u’text’: u'< R1500′}, means that the question was “Monthly household

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.com/f/ihJd4in3Tt7Fr8KZe6UvEC/0

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 current_date in postgresql is

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 have something like following one:

Advertisement