Skip to content
Advertisement

Tag: postgresql

How to check whether a user has records in past?

Sample Table Above sample table consists Users info who completed certifications. An user can also go for retraining but he/she should have completed a course before retaking it. User Id: 2 is retrained on certificate 2, he has a record in past (Completed same certificate earlier), but User id: 3 has no certificates in past but he directly choose retraining.

Junction table in PostgreSQL

I have two tables I created a junction table called “recipes_ingredients” My first question is: is it correct how I created the “recipes_ingredients” table? Do I need the “id” or I can just have the two foreign keys “fk_recipe” and “fk_ingredient”? And the second one is if it’s possible to autopopulate the junction table when I insert a record in

How to insert value to a column as a result of geometry of another column in the same table

i have the database table posted below. the two columns geometryOfCellRepresentativeToTreatment and geometryOfCellRepresentativeToBuffer are of type geometry. and their value is equal the the geometry of the column fourCornersRepresentativeToTreatmentAsGeoJSON_ and fourCornersRepresentativeToBufferAsGeoJSON respectively. how can i insert the value into the latter columns as geometry of the former columns table: data_to_be_inserted: image Answer Just set the geojson strings to the geometry

How to aggregate upvote and post tables together in postgres?

I’m looking for a way to aggregate posts and the upvotes related to that post together using PostgreSQL. I want to make it similar to reddit’s upvote systems, where upvotes come already fetched and don’t need to be loaded on client side. I have made these simple tables. upvotes.sql users.sql posts.sql Basically I want to make my response look something

How can multiple unique in partition tabale?

I have a SQL table like below. I have a table. I need to unique order_no column with user_id column. there is no any problem. But I have to unique data_time column because of I use partition. but date_time column has to be separated with user_id and order_no. By the way I don’t want like this unique (user_id, order_no, data_time)

Return type of table function with joined result-set

As a follow-up to Parametrized CTE, What would be the following return type for creating the following table function in postgres which returns a result-set containing two joined tables? For example, converted to a function it might be something along the lines of: Answer You have two options. You can create a custom type containing all the resulting columns. Then

Parametrized CTE

Let’s say I have a table-function that I’m currently doing with a CTE, for example: Is there a way to parametrize the CTE such that I can do something like: And then I could call it as: Or what is the proper way to parametrize a table function in a postgres (CTE?) Note that I don’t necessarily know the output

Advertisement