Can I SELECT all the bult-in functions in SQL Server? - sql

Is it possible to display every built-in function (like LEFT, SIN, IIF etc.) with a query?

Documentation or syntax highlighting definition from official tool:
Azure Data Studio - syntax support
{
"match": "(?i)\\b(avg|checksum_agg|count|count_big|grouping|grouping_id|max|min|sum|stdev|stdevp|var|varp)\\b",
"name": "support.function.aggregate.sql"
},
{
"match": "(?i)\\b(cast|convert|parse|try_cast|try_convert|try_parse)\\b",
"name": "support.function.conversion.sql"
}, ...
Searching for: "name": "support.function
Idea - Not tested: Maybe it is possible to extract that data from system database - Resource
Resource Database
The Resource database is a read-only database that contains all the system objects that are included with SQL Server.

No, the functions documentation is your best alternative. It gives a structured overview of all supported built-in functions.
Using any decent IDE will provide some highlighting and auto-completion features for function names.

Related

How to achieve generic Audit.NET json data processing?

I am using Audit.Net library to log EntityFramework actions into a database (currently everything into one AuditEventLogs table, where the JsonData column stores the data in the following Json format:
{
"EventType":"MyDbContext:test_database",
"StartDate":"2021-06-24T12:11:59.4578873Z",
"EndDate":"2021-06-24T12:11:59.4862278Z",
"Duration":28,
"EntityFrameworkEvent":{
"Database":"test_database",
"Entries":[
{
"Table":"Offices",
"Name":"Office",
"Action":"Update",
"PrimaryKey":{
"Id":"40b5egc7-46ca-429b-86cb-3b0781d360c8"
},
"Changes":[
{
"ColumnName":"Address",
"OriginalValue":"test_address",
"NewValue":"test_address"
},
{
"ColumnName":"Contact",
"OriginalValue":"test_contact",
"NewValue":"test_contact"
},
{
"ColumnName":"Email",
"OriginalValue":"test_email",
"NewValue":"test_email2"
},
{
"ColumnName":"Name",
"OriginalValue":"test_name",
"NewValue":"test_name"
},
{
"ColumnName":"OfficeSector",
"OriginalValue":1,
"NewValue":1
},
{
"ColumnName":"PhoneNumber",
"OriginalValue":"test_phoneNumber",
"NewValue":"test_phoneNumber"
}
],
"ColumnValues":{
"Id":"40b5egc7-46ca-429b-86cb-3b0781d360c8",
"Address":"test_address",
"Contact":"test_contact",
"Email":"test_email2",
"Name":"test_name",
"OfficeSector":1,
"PhoneNumber":"test_phoneNumber"
},
"Valid":true
}
],
"Result":1,
"Success":true
}
}
Me and my team has a main aspect to achieve:
Being able to create a search page where administrators are able to tell
who changed
what did they change
when did the change happen
They can give a time period, to reduce the number of audit records, and the interesting part comes here:
There should be an input text field which should let them search in the values of the "ColumnValues" section.
The problems I encountered:
Even if I map the Json structure into relational rows, I am unable to search in every column, with keeping the genericity.
If I don't map, I could search in the Json string with LIKE mssql function but on the order of a few 100,000 records it takes an eternity for the query to finish so it is probably not the way.
Keeping the genericity would be important, so we don't need to modify the audit search page every time when we create or modify a new entity.
I only know MSSQL, but is it possible that storing the audit logs in a document oriented database like cosmosDB (or anything else, it was just an example) would solve my problem? Or can I reach the desired behaviour using relational database like MSSQL?
Looks like you're asking for an opinion, in that case I would strongly recommend a document oriented DB.
CosmosDB could be a great option since it supports SQL queries.
There is an extension to log to CosmosDB from Audit.NET: Audit.AzureCosmos
A sample query:
SELECT c.EventType, e.Table, e.Action, ch.ColumnName, ch.OriginalValue, ch.NewValue
FROM c
JOIN e IN c.EntityFrameworkEvent.Entries
JOIN ch IN e.Changes
WHERE ch.ColumnName = "Address" AND ch.OriginalValue = "test_address"
Here is a nice post with lot of examples of complex SQL queries on CosmosDB

Select * Except particular properties in Cosmos DB with SQL API

Consider the following, I have a document that looks something like this:
"id": 2
"properties": {
"desired": {
"Property1": 10,
"Property2": 1,
"Property3": 1,
"$metadata": {
...
},
"$version": 53
}
},
I want to get everything from the document EXCEPT $metadata and $version The obvious solution would be to:
SELECT c["Property1"], c["Property2"] .... FROM c where c["id"] = "2"
However, my document may expand dynamically, hence why the above is suboptimal. I therefore figured that it may be better to exclude just $metadata and $version. I looked at different "interesting" solutions here on stackoverflow, amongst which one suggests to create a temporary table.
Unfortunately, the query needs to be very efficient, because I want to reduce the amount of RUs used. Also I really want to avoid handling the exclusion in the code.
Therefore, how do I exclude particular "columns" from my document, without writing an excessively long query, which may include creating temporary tables.
Cosmos DB does not support "Project Away". You will need to specify properties to project or use * and return all of them.

Is it possible to add a custom keyword?

Using Json.NET schema, I am trying to create the simple schema:
{
"type": "object",
"customKeyWord": "customValue",
"properties": [
]
}
Is it possible to create a custom keyword at the top level like this?
Yes. Specs:
6.4. Extending JSON Schema
Implementations MAY define additional keywords to JSON Schema. Save for explicit agreement, schema authors SHALL NOT expect these additional keywords to be supported by peer implementations. Implementations SHOULD ignore keywords they do not support.

Azure Search API does not find indexed document despite correct query

Using Azure Search REST API v2016-09-01, the following query find the expected document:
?queryType=full&search=id:3119443 AND name:du*
{
"value": [
{
"#search.score": 4.425995,
"id": "3119443",
"name": "dupond"
}
]
}
Whereas the following broader query (searching d* instead of du*) does not find the same document:
?queryType=full&search=id:3119443 AND name:d*
{
"value": []
}
The name field uses a custom analyzer with the Whitespace tokenizer and the WordDelimiterTokenFilter, AsciiFoldingTokenFilter and Lowercase token filters.
Most of the indexed documents are correctly found when searching their first name letter.
The issue is 100% reproducible on those specific documents, for which I don't find anything special.
The Search Service is a "Standard" tier (1 replica, 1 partition, 1 search unit), with the index containing 3,000,000+ documents.
Thank you.
Thanks for reporting the issue. As commented, this is a regression introduced in a recent change. The bug has been fixed. Thanks.

how to query in ravendb studio?

I have no problem querying RavenDB from code, but sometimes a quick lookup directly to RavenDB would be nice. Unfortunately, I cannot figure it out despite tips that it uses Lucene syntax.
For example, I have a RegionLocation document:
{
"RegionId": 804291854,
"Name": "Miami",
"Description": null,
"DbRowStatus": 0,
"CreatedBy": "Zorro",
"UpdatedBy": null,
"DeletedBy": null,
"CreatedOn": "2013-06-05T18:31:37.4332753",
}
I haven't had any luck with quering it. RegionLocation.Name: M* returns no results.
Any idea what I am doing wrong?
Assuming you already have an index that has the name mapped, or you are building a new dynamic index against the RegionLocation documents, then the syntax for your query would just be:
Name: M*
I agree that the documentation could be better - especially the in-application help. But you can find most of what you need to know here.
UPDATE
This was raised as Issue #1250, and closed in RavenDB 2.5.2750. The studio now includes easily accessible help:
The popup shows when you hover over the (i) icon, and the "Query syntax online" link points at the relevant Lucene documentation.