Having issues getting rid of this error. I’m trying to use Digital Ocean to deploy my Django app. I configured Postgres, but when I’m trying to register a new user in my app, I get this problem. I’…
Tag: sql
How do I catch a query exception in laravel to see if it fails?
All I’m trying to do is verify a query. Without that erroring out, I’d like to know it failed so I can return a response that states “Error: table does not exist” or the generic error. Answer The simplest way to catch any sql syntax or query errors is to catch an IlluminateDatabaseQuer…
Raills: Get SQL generated by delete_all
I’m not particularly familiar with Ruby on Rails, but I’m troubleshooting an issue we’re experiencing with a rake job that is supposed to be cleaning database tables. The tables grow very large very …
Select all from table where the rows has the highest id of all those with the same foreign keys
So I have a posts table with a author_id foreign key and a published status (bool). I want to select all the most recent (highest id) published posts for an author (all those with the same author_id foreign id). Right now I can get the highest for a group of foreign keys But this only returns the highest id f…
SQL inner join syntax error
I have this error. I am new to SQL and can’t figure what is wrong with my syntax. I changed my INTERSECT statement to inner join realizing SQL does not accept such syntax. However I continue to get an …
Calculating age derived from current date and DOB
I’m trying to calculate the age of a user based on the current year and his year of birth, but something in my syntax appears to be incorrect and I can’t spot it. CREATE TABLE Normal_Users( …
Show results in popup
This code is working fine to show results on the page itself but I want to show the results in a popup. We have linked the code to a database and it is retrieving the expected result, but how can I use jQuery to display division in a popup or dialogue box? Also it should be responsive. Answer Using jQuery
EF – AND NOT EXISTS (SELECT 1 …) with Entity Framework
I am trying to run this query using Entity Framework in my ASP.NET MVC project but I am not succeeding. Could anyone help me do this using LINQ? TABLES: Answer The direct equivalent LINQ construct of SQL NOT EXISTS (…) is !Any(…). So translates to
Creating a mySQL sub query to list distinct rows from two queries
I have two queries: and The first query returns around 4000 values, the second query returns around 4100. I’m attempting to create a query that will return the rows which are distinct between the two values, I’m attempting this by using a nested or sub query but I’m struggling with syntax he…
Select timestamp with time zone, but ignore seconds
I’m selecting a timestamptz from a PosgreSQL database. I want my SELECT to return only the date, hours and minutes. No seconds. Can I set the date format in my psql SELECT to accommodate this? Answer You can use date_trunc() to truncate seconds and still return a timestamptz: Or you can use to_char() to…