How do I determine if NULL is contained in an array in Postgres? Currently using Postgres 9.3.3. If I test with the following select it returns contains_null = false. select ARRAY[NULL,1,2,3,4,NULL]:…
MYSQL show all rows where no duplicates found
If I had a set of data like this: What would be the SQL query to display only “James Peters”. So I am not wanting to remove duplicates (DISTINCT command) but rather show all rows where there are no duplicates found. Answer You would use group by for this with a having clause:
Grant privileges on future tables in PostgreSQL?
I am running PostgreSQL 9.3.1. I have test database and backup user which is used to backup the database. I have no problems with granting privileges to all current tables, but I have to grant privileges each time the new table is added to schema. Is it possible to grant access to tables which will be created…
Real, mathematical “modulo” operation in Postgres?
In Ruby: In Postgres: I can easily write one myself, but I’m curious whether Postgres has a real modulus operation, as opposed to remainder after division. Answer will return 22 instead of -2
How to merge all integer arrays from all records into single array in postgres
I have a column which is of type integer array. How can I merge all of them into a single integer array? For example: If I execute query: I get result set as: How can I get {1,2,3,4,5} as final result? Answer You could use unnest to open up the arrays and then array_agg to put them back together:
How to write a program to automatically download a file from email
I have an email account (like gmail or something) that gets a daily email with a file attached to it that has some data in it. Is there a way to have a program check the email everyday, say at midnight or something, download that file, and store the contents into a SQL database? I’m familiar with Java, …
Import sql file in node.js and execute against PostgreSQL
I’m looking for an efficient way to take a raw sql file and have it executed synchronously against a postgres database, akin to if you ran it through psql. I have an sql file which creates all databases, imports data, etc. I need to execute this using node.js but cannot find any module which does this a…
change sql permission to prevent SQL injection
I’m currently making a website using PHP and MYSQLi. And I’ve been read a lot about SQL injection. As answered on other questions from StackExchange, 2 ways of prevent it is by using prepared statement and escaping string. Since I’m not able to do prepared statement (I’ve tried to make…
SQL query search by ID and get another attribute of the record
I’m working on a DB where I need to search MAX(ID), where ID is an autonumber, (basically the most recent record/last record) and then when found I want to get the receipt number. e.g. receipt table …
SSRS – Vertical merge cells in Details rows
I have stored procudure which returns some data like this: Trade mode;Area;Production place;Commodity;Reseller;Min_sell_price;Max_buy_price;Trans_count;Volume;avg_price;change_avg_price;…