Category «Postgres»

How to create a postgresql database view for same table join on same column to get the latest record

How to create a postgresql database view(table_view) for same table(same_table) join on same column(someid) to get the latest record max(a.id) CREATE OR REPLACE VIEW table_view AS SELECT i.id,i.created_at AS time_in,i.action AS action_in,i.alert_msg AS alert_in, o.created_at AS time_out,o.action AS action_out,o.alert_msg AS alert_out FROM same_table i INNER JOIN same_table o ON i.someid = o.someid WHERE i.id IN …

How to use Json/jsonb in Postgres

How to use JSONB/Json in Postgres Now that we have gone over some of the benefits and use-cases for storing JSON data in Postgres, let’s take a look at how it’s actually done. Defining columns JSONB columns are just like any other data type now. Here’s an example of creating a cards table that stores …