I’m working on a Rails application that utilizes the Postgres JSON data type. I have a JSON column called data in a table called reports. Let’s say I have multiple entries like this: What I would like to do is return the different combinations of entries that have the same album, src, and backgrou…
Modeling a prescription/medicine usage set of database tables
Not sure how to go about modelling medication taken at a point in time in a relational database. Each way I have thought of so far seems to have redundant data. Need to be able to have a user say I …
MYSQL toggle enum values on each call
I want this to be like this. I have an ENUM column with 0 AND 1, i want to toggle between these two values on each query. I tried this, but it leaves the column empty. Thanks. Answer I don’t like enum for various reasons. Especially when you use it to store 0 and 1 it can be confusing, yes,
Text Qualifier syntax in PDW dwloader
I am using dwloader utility to load data into PDW. My dwloader syntax is given below: I got the data loaded into the table. But all the varchar columns have data within double ‘quotes’. My text file is commma delimited. Any idea on how to include the text qualifier in the above syntax? Answer I fi…
Getting distinct values with the highest value in a specific column
How can I get the highlighted rows from the table below in SQL? (Distinct rows based on User name with the highest Version are highlighted) In case you need plain text table: What I have so far is (works for one user) Answer this might help you : sql fiddle
Anonymous type result from sql query execution entity framework
I am using entity framework 5.0 with .net framework 4.0 code first approach. Now i know that i can run raw sql in entity framework by following It’s working perfectly but what I want is return anonymous results. For example I want only specific columns from student table like following It is not working…
SQL server how to do string comparison with left join
I have two tables: the entry table (one nvarchar column called entry) and the disease table (one nvarchar column called disease). I would like to produce another table that has all the entry-disease …
Postgres constraint for unique datetime range
My table has two columns: startsAt endsAt Both hold date and time. I want to make following constraint: IF both columns are NOT NULL then range between startsAt and endsAt must not overlap with other ranges (from other rows). Answer You can keep your separate timestamp columns and still use an exclusion const…
Oracle SQL CASE WHEN ORA-00932: inconsistent datatypes: expected CHAR got NUMBER 00932. 00000 – “inconsistent datatypes: expected %s got %s”
Getting error ORA-00932: inconsistent datatypes: expected CHAR got NUMBER 00932. 00000 – “inconsistent datatypes: expected %s got %s” When i run the following query SELECT distinct CASE when t….
How to compare dates which is stored as String(varchar) in database?
I have a database(table), in which 2 fields are: fromdate varchar(20) todate varchar(20) Dates are stored in this fashion: YYYY-MM-DD HH:mm:ss For ex: ‘2014-10-30 10:10:10’ in database. Now I want …