Skip to content
Advertisement

Tag: postgresql

How to convert fields to JSON in Postgresql

I have a table with the following schema (postgresql 14): message are only string, phrases. sentiment is a string, only one word classification are string but can have 1 to many word comma separated I would like to create a json field with these columns, like this: Also, if possible, is there a way to consider the classification this way:

SQL Group by JSON arrays

So I have a JSON variable (var2), which is an array. I have the following data: I’m trying to write a query that gives back the number of dollars and the machines per group: Example: I’m not used to JSON arrays and it’s kinda tricky for me. I’ve tried many things and I can’t find much documentation with examples for

Postgres : using computed variable in a SELECT statement part 1/2

I’m having a SELECT statement as follow (doesn’t work): Is there a way to “inject” here the “variable” age_normin the query ? EDIT: Asked a similar question here, but this time with an additional column in the SELECT statement, which is the use case I’m trying to solve Answer We can calculate the age_norm column in a subquery and then

Insert aggreated data from one SQL table to another (Postgres)

I have two SQL tables. This is Votes: and this is votes_aggregate: As you can see each entry in the votes table is a unique vote. I want to aggregate all the individual votes mapping to the same (catalog_item_id, listing_id) to a unique entry in the aggregate_votes table (2nd table). My Postgres skills are pretty weak so I’m struggling to

How to create temporal table from current and history?

Let’s say I have a current table that looks like this: and I have a history table that looks as such: How can I build a temporal table such as the following in pure SQL? I am using a PostgresDB is dialect helps! I know I can do this in Python, I’m stuck on calling dynamically named columns using the

creating a full text index in SQL database

I am searching for a database solution for real full text indexing. I have read Postgres’ full text search chapter but it describes text searching which is not a “full” index and it is heuristic in nature. However I found this https://pgpedia.info/f/fulltextindex.hml contrib/fulltextindex module which sound promising. So my questions are as follows. why was it removed in PostgreSQL 8.1?

PostgreSQL: Create array by grouping values of the same id

Given the following input data: id category 1 A 1 B 2 A 2 R 2 C 3 Z I aim aiming to get the following output table: id categories 1 {“A”,”B”} 2 {“A”,”R”,”C”} 3 {“Z”} using the following query: But what I get is the following table: id categories 1 {“A”,”B”,”R”,”C”,”Z”} 2 {“A”,”B”,”R”,”C”,”Z”} 3 {“A”,”B”,”R”,”C”,”Z”} How can I obtain

Advertisement