I have a rather complex peewee query that looks like that: This one actually works, generating the following SQL query: But I don’t really want to use RIGHT_JOIN as it isn’t supported by SQLite. When trying to query using the subquery query and JOINing the Solution table into the subquery’s result, I get an error from peewee. The new query:
Tag: postgresql
Transfer data from one table to another with both table having same id, in Postgres
I have 2 tables. TBL_A and TBL_B. I want to update TBL_A so that A_NAME = B_NAME, where A_LA = B_LA. How do I do this? This is just s sample data. In the real table, I have thousands of records on each table. I tried connecting both tables using View, but it seems that the view can’t be updated.
insert datetime from csv to postgres error
I have a csv file: output: And then I tried to insert the file data into postgres database: Error: It works in psql client. I thought it is the string character ‘T02’ issue,so I use: Then the error became: Then I thought I need convert it to datetime first: Same error as the last one. Then I did some research:
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