query and subquery join in laravel

i m trying this on laravel but i m getting error like this SQLSTATE[42601]: Syntax error: 7 ERROR: subquery in FROM must have an alias LINE 3: (select * from subcategory a inner join s... HINT: For example, FROM (SELECT ...) [AS] foo. (SQL: selec...
more »

2017-04-19 10:04 (2) Answers

Coalesce results in a QuerySet

I have the following models: class Property(models.Model): name = models.CharField(max_length=100) def is_available(self, avail_date_from, avail_date_to): # Check against the owner's specified availability available_periods ...
more »

2017-04-18 10:04 (2) Answers

Is it okay to validate JSON at PostgreSQL side?

Writing APIs I used to validate all input parameters on the Java (or PHP, whatever) side, but now we moved our DBs to PostgreSQL which gives us great JSON features, like building JSON from table rows and a lot more (I didn't find anything we can't to...
more »

2017-04-16 21:04 (1) Answers

PostgreSQL indexing JSONB array

Here is my json jsondata ------------------------------------ {"key1": 1, "keyset": [10, 20, 30]} {"key1": 1, "keyset": [10, 20]} {"key1": 1, "keyset": [30]} {"key1": 1 } {"key1": 1, "key2": 1} I tried creating index keyset for above example 1st ...
more »

2017-04-15 20:04 (1) Answers

SQLAlchemy sum function with bounds

In sqlalchemy (postgresql DB), I would like to create a bounded sum function, for lack of a better term. The goal is to create a running total within a defined range. Currently, I have something that works great for calculating a running total witho...
more »

2017-04-12 16:04 (2) Answers

Ordering queryset by filtered child objects

I have the following (simplified) data model, see visual representation below the post: Articles, which have Attributes Attributes refer by PK to a Type, which have a field code Attributes have a field value The value refers to the field uuid in an...
more »

2017-04-10 19:04 (0) Answers

Is an index on a SET column useful?

The following question is framed with a particular lean towards MySQL and PostgreSQL, but I'd also be interested in answers regarding other database systems. I'm designing a database and the SET column type appears to fit the bill in a few cases. On...
more »

2017-04-10 02:04 (2) Answers

Java/javaFX: new connection to db for every query?

So, I am creating an application in javaFX (for learning purposes only) which mainly consists of a tabpane with sub-fxmls for each tab. Each tab consist of a tableview with data collected from a database. To connect to the database I have a separate ...
more »

2017-04-08 02:04 (0) Answers

Rails - To use polymorphism or not for performance

I have 9 models in my applications that use a paperclip column for profile photo and cover photo. I have 2 options (at least from my limited understanding) Have a polymorphic model ProfilePicture that is associated with the other 9 models. Add the...
more »

2017-04-06 17:04 (1) Answers

Django fails to find psycopg2 module

I am installing python 3.5, django 1.10 and psycopg2 2.7.1 on Amazon EC2 server in order to use a Postgresql database. I am using python 3 inside a virtual environment, and followed the classic installation steps: cd /home/mycode virtualenv-3.5 p3en...
more »

2017-04-06 12:04 (1) Answers

How to install luasql on Linux Ubuntu 16?

Thanks to the help of the StackOverflow community, I was able to correctly install luasql on my computer running Linux CentOS 7. Now I have a similar problem on Linux Ubuntu 16. I tried the following commands: sudo apt-get -y install lua-sql-postgr...
more »

2017-04-03 18:04 (2) Answers

SQL model for flexible and configurable attributes

I'd like to design an application which will eventually fuel a configurable data-driven form. Each user should be able to customize what fields appear in their own forms, and configure new form types to collect different sets of data. One user may ...
more »

2017-04-01 23:04 (1) Answers

Recognize if not enough resources during timeframe

i need an idea how to solve the following problem. Lets say i have one group with given timeframe (8:00-12:00) and i can assign resources (people) to it. Each resource can have a custom timeframe (like 9-10, 9-12,8-12 etc.) and could be assigned mul...
more »

2017-03-30 09:03 (2) Answers

Update jsonb column

I'm trying to update user facts inside of a column in a Postrgres db in the form designated here. jsonb currently in data column and waiting to be updated: data = { "type1" : ["value1", "value2"], "type2" : ["value3"], "type3" : ["value4"] } jsonb...
more »

2017-03-29 23:03 (1) Answers

Django set autofield value in bulk_create

I'm trying to bulk_create a lot of records in a new table in my PostgresQL db. The primary key on the table is an AutoField called id. As of Django 1.10 (which I'm using), this should work in Postgres: https://docs.djangoproject.com/en/1.10/ref/mod...
more »

2017-03-27 22:03 (1) Answers