Does the Oracle NoSQL Database SQL query support slice for an array? - nosql

One of our applications stores a number of arrays in a table. We need to query these arrays in many different ways.
Does the Oracle NoSQL Database SQL query support the following?
Simple examples:
Let's assume the following is part of the table myTable:
myarray array(integer)
We need to implement the following queries:
SELECT username, myarray[1] AS t FROM myTable
SELECT username, [myarray[0:2]] AS t FROM myTable

Yes, both queries are supported.

Related

If a Postgres DB has unique IDs across its tables, how do you find a row using its ID without knowing its table?

Following the blog of Rob Conery I have set of unique IDs across the tables of my Postgres DB.
Now, using these unique IDs, is there a way to query a row on the DB without knowing what table it is in? Or can those tables be indexed such that if the row is not available on the current table, I just increase the index and I can query to the next table?
In short - if you did not prepared for that - then no. You can prepare for that by generating your own uuid. Please look here. For instance PG has uuid that preserve order. Also uuid v5 has something like namespaces. So you can build hierarchy. However that is done by hashing namespace, and I don't know tool to do opposite inside PG.
If you know all possible tables in advance you could prepare a query that simply UNIONs a search with a tagged type over all tables. In case of two tables named comments and news you could do something like:
PREPARE type_of_id(uuid) AS
SELECT id, 'comments' AS type
FROM comments
WHERE id = $1
UNION
SELECT id, 'news' AS type
FROM news
WHERE id = $1;
EXECUTE type_of_id('8ecf6bb1-02d1-4c04-8875-f1da62b7f720');
Automatically generating this could probably be done by querying pg_catalog.pg_tables and generating the relevant query on the fly.

Select query on multiple databases

What I am trying to do is verify a URL. I just need to be able to select that single value from all databases that we have currently in SQL Server 2008. All the databases are the same, just multiple instances of the same database for different users.
I am looking to pull one item from one table in each database.
Each database contains a table SETTINGS and within that table a value for MapIconURL. I need that value from each table from within each database. I am looking at around 30 or so databases that would have this value.
So I found the "undocumented" Stored Proc sp_MsForEachDb and have working....to a point.
The code I am using is this:
EXEC sp_MsForEachDb 'use ?; SELECT "?" as databasename,SETTINGSKEYID, SECTION, NAME, INIVALUE, DESCRIPTION
FROM ?.dbo.SETTINGS
WHERE [NAME] = "MapIconURL"'
I have noticed that it is not selecting all the databases, but that it is also selecting the master table as well as other system tables, and am thinking that may be why it is not selecting all tables. Is there a way to exclude the system related tables?
If the number (and name) of the databases is fixed, then you could simply do:
SELECT MapIconUrl FROM db1.dbo.SETTINGS
UNION ALL
SELECT MapIconUrl FROM db2.dbo.SETTINGS
...
However, if either the number or names of the databases is not fixed, then you have to build the query dynamically.
First, run a query such as SELECT name FROM master..sysdatabases to get the names of the databases.
Then, loop over the result set (in T-SQL, use a CURSOR) and build your query and execute it (in T-SQL, use sp_executesql).

How to join Non-Spatial table to Spatial table in Postgis database (Both tables are in different database)

I need to join a Non-spatial table to Spatial table, but both are in different database.
Spatial_table(dbname:dist)
gid
district_name
district_code
geom
Non_Spatial(dbname:census)
ID
district_code
population
male_popu
female_popu
Can anyone please suggest me, How to relate the above to tables to get the query result for the population of specific district?
Also can anyone tell me about the difference between Joining and Relating of two tables.
You can't do a cross-database join in PostgreSQL. The way MySQL uses databases PostgreSQL uses schemas.
There is an add-on called dblink though which lets you query another PG database (even on another machine).
That's not going to be very efficient with a join though, because it's going to have to transfer a whole table in one direction or the other to do the comparisons. If you are going to regularly want to join tables they need to be in the same database (but perhaps separate schemas).

How to access multiple tables in sqlite3 for iphone sdk

In a single database example abc.sqlite has the 4 tables (cases,questions,category and options).
Each table has different columns.
How to get the data from table1 column1, table2 column 2.
How to write queries for that.
You want to learn more on SQL92 the query language for the databases, that let you select and insert data to your tables. Actually the sqlite documentation is one of the best because contains the useful syntax diagrams that you find on http://sqlite.com/lang.html

PostgreSQL join across 2 databases

I am new to PostgreSQL. I have 2 databases in PostgreSQL 9.0, db1 and db2, and with db2 I have read only access. I want to create a stored function that would be otherwise easily accomplished with a JOIN or a nested query, something PostgreSQL can't do across databases.
In db1, I have table1 where I can query for a set of foreign keys keys that I can use to search for records in a table2 in db2, something like:
SELECT * from db2.table2 WHERE db2.table2.primary_key IN (
SELECT db1.table1.foreign_key FROM db1.table1 WHERE
db1.table1.primary_key="whatever");
What is the best practice for doing this in Postgres? I can't use a temporary tables in db2, and passing in the foreign keys as a parameter in a stored function running in db2 doesn't seem like a good solution.
Note: the keys are all VARCHAR(11)
You'll want to look into the db_link contrib.
As an aside if you're familiar with C, there also is a cute functionality called foreign data wrappers. It allows to manipulate pretty much any source using plain SQL. Example with Twitter:
SELECT from_user, created_at, text FROM twitter WHERE q = '#postgresql';