After having created a temporary table and declaring the data types like so; How do I then insert the relevant data which is already held on a physical table within the database? Answer
Tag: sql
PL/pgSQL SELECT into an array
Here’s my function declaration and part of the body: I want team_ids to be an array of ints that I can then use in the UPDATE statement. This function give me errors like this: Answer Faster and simpler with a FROM clause in your UPDATE statement: That aside, while operating with an array, the WHERE cla…
FULL OUTER JOIN vs. FULL JOIN
Just playing around with queries and examples to get a better understanding of joins. I’m noticing that in SQL Server 2008, the following two queries give the same results: Are these performing exactly the same action to produce the same results, or would I run into different results in a more complicat…
SQL select elements where sum of field is less than N
Given that I’ve got a table with the following, very simple content: I would like to select N messages, which sum of verbosity is lower than Y (for testing purposes let’s say it should be 70, then correct results will be messages with id 1,2,3). It’s really important to me, that solution sho…
Java socket client/server
Hi i am trying to get some data about a socket client connecting to a mutltythreaded server process in the same machine. The server thread is triggered correctly and the client ip is retreived ok, but i cant seem to be able to send a string through the connection. THE CLIENT THE SERVER THREAD The line sent th…
rails scope and joins
I have tried everything i thought would work for this and am turning up nothing. in rails 3, I need to find all users with a cd player in their car. A car has one user and one radio, and a user belongs to a car, and a radio has many cars. I am stumbling on how I would perform
Differences between PostgreSQL and MySQL for PHP developers
For a project where most queries on the database will include requirements like “within an polygon” I have come to think about choosing PostgreSQL with PostGIS instead of MySQL, which I have previously mainly used. Mainly because PostgreSQL has more GIS functions. However, I am uncertain how to ev…
How to simulate a deadlock in SQL Server in a single process?
Our client side code detects deadlocks, waits for an interval, then retries the request up to 5 times. The retry logic detects the deadlocks based on the error number 1205. My goal is to test both the deadlock retry logic and deadlock handling inside of various stored procedures. I can create a deadlock using…
SQL Server database backup file (.bak ) file gets corrupted
I have been working on a SQL Server database designing since long now and I have observed that when a .bak file is mailed or kept and downloaded from ftp site, it gets corrupted. When I try to restore, it gives me 3013 error code with messsage: “Backup or restore operation terminating abnormally. I trie…
How to return default value from SQL query
Is there any easy way to return single scalar or default value if query doesn’t return any row? At this moment I have something like this code example: How to do that in better way without using IF-ELSE? Answer Assuming the name is not nullable and that Id is unique so can match at most one row.