Skip to content

Tag: postgresql

How to add a column default?

I created a Postgres DB which contains 5 tables. Then I realized that the column student.student_id lacks a column default to generate an UUID: Knowing that some tables are linked to the student table, how can I add to the function as column default for student_id so that the result will be: Answer Use ALTER TABLE: Column defaults do not

SQL write a query, question from interview problem

At the beginning I need to mention that I am not very good at SQL so I would like to ask you. Here is a tables relation: tables What I need to do with them is “Show name, surname and number of movies those directors (Re┼╝yser means director), who made more movies that the average number is for all directors.

how to get json result to fixed number by grouping in postgresql?

I want to get expected results to one query execution. the “where” clause should one value. so I can’t use this query as sub-query of main-query. could you tell me how to do it? Sample sql query: Expected results: results [{“id”:1,”name”:”hello”},{“id”:4,”name”:”good”},{“id”:7,”name”:”world”}, {“id”:9,”name”:”happy”}] [{“id”:10,”name”:”funny”},{“id”:12,”name”:”stack”},{“id”:15,”name”:”queue”},{“id”:18,”name”:”map”}] [{“id”:19,”name”:”list”},{“id”:23,”name”:”code”}] Answer demo: db<>fiddle Convert your records into JSON objects Create a row count using the row_number()