How to find if SORTKEY is defined and how it is defined from catalog tables? - sql

I am creating a view for generating the DDLs for the tables. I am stuck at a point where I am unable to find how the SORTKEY is defined like SORTKEY AUTO or SORTKEY(columns).
I saw there is a column "attsortkeyord" in the pg_attribute table but it gives numerical values which only tell the order of columns defined in sort keys.
There is a system view named "svv_table_info" which has column "sortkey1". This actually tells what exactly I required like AUTO(EVEN) or AUTO(ALL) but this view I am unable to use with other queries inside my main view.
Whenever I use "svv_table_info" I get an error "Function not supported" for almost all functions like text, format_type, etc.
Can anyone please help me either how to get details from catalog tables or how to deal with this error while using "svv_table_info"?

Related

How to reference the latest table from a manually partitioned BigQuery table

We have a manually partitioned "video metadata" table being fed fresh data each day. In our system, old data is only kept for historical reasons since the latest data is the most up to date.
What we cant figure out is how to reference only the latest partition in this table using LookML.
So far we have attempted to store views in BigQuery. We have tried and failed to store a simple "fetch the newest partition" query as a view, in both standard and legacy SQL, and upon some searching, this seems to be by design, even though the error message states "Dataset not found" instead of something more relevant.
We've also tried to build the filtering into Looker, but we're having trouble with getting things to actually work and only having the latest data returned to us through it.
Any help would be appreciated.
We've managed to find a solution, derived tables
We figured that since we couldn't define a view on BigQuery's side, we could do it on Looker's side instead, so we defined the table in a derived table block inside a view.
derived_table: {
sql: SELECT * FROM dataset.table_*
WHERE _TABLE_SUFFIX = (
SELECT max(_TABLE_SUFFIX) FROM dataset.table_*
);;
sql_trigger_value: SELECT max(_TABLE_SUFFIX) FROM dataset.table_*;;
}
This gave us a view with just the newest data in it.

Why would Access spontaneously start displaying a non-existant table in a query?

I updated a simple Access select query, adding four fields from the single table the query uses. When I then attempted to edit data in the form that references that query, Access did not allow any edits. After poking around at other possible edit rights problems I went back to the query design, and saw this:
The table CC_Tracker_1 does not exist in the database, nor is there a query by that name, as you can see in the object list:
In the design view, CC_Tracker_1 displays as an exact copy of CC_Tracker. Additionally, the four fields I added had CC_Tracker_1 listed as their table of origin.
Deleting CC_Tracker_1 from the query and re-adding the fields from CC_Tracker fixed the problem, but I'm very curious as to how this could happen.
Edit to add: This is the SQL Access generated. As you can see the alias it created isn't used anywhere in the code except in the variable list. Why it would do this is still the question:
SELECT CC_Tracker.LAST_NAME, CC_Tracker.FIRST_NAME, CC_Tracker.MRN, CC_Tracker.RIN,
CC_Tracker.SUBSCRIBER_ID, CC_Tracker.ASSIGNED, CC_Tracker.Letter, CC_Tracker.[1stCall],
CC_Tracker.CHRA, CC_Tracker.[ICP/Review], CC_Tracker.F2F, CC_Tracker.ICTCont,
CC_Tracker.ICTSheet, CC_Tracker.ICP2MD, CC_Tracker.SigPg, CC_Tracker.HTR_1st_cont,
CC_Tracker.HTR_2nd_cont, CC_Tracker.HTR_3rd_cont, CC_Tracker.HTR_Letter,
CC_Tracker.CLOSE, CC_Tracker.Comments, CC_Tracker.CHRA_Next, CC_Tracker.ICP_Next,
CC_Tracker.F2F_Next, CC_Tracker.ICT_Next, CC_Tracker_1.Final_Follow, CC_Tracker_1.BH_SA,
CC_Tracker_1.Readmitter, CC_Tracker_1.CCM, CC_Tracker.ASSIGNED_CARE_COORDINATOR, CC_Tracker.Final_Follow
FROM CC_Tracker, CC_Tracker AS CC_Tracker_1
WHERE (((CC_Tracker.ASSIGNED_CARE_COORDINATOR)=[Forms]![frmCoord_Selector]![cmbCoords]))
OR (((([CC_Tracker].[ASSIGNED_CARE_COORDINATOR])
Like [Forms]![frmCoord_Selector]![cmbCoords]) Is Null));
If you look at the SQL that is generated for the query, you will see that it has created an alias called CC_Tracker_1 for the CC_Tracker table.
Your query may need to be rewritten to exclude this alias, and any incorrect joins.
If you post the actual query generated, we will be able to help fix it.

Bigquery return nested results without flattening it without using a table

It is possible to return nested results(RECORD type) if noflatten_results flag is specified but it is possible to just view them on screen without writing it to table first.
for example, here is an simple user table(my actual table is big large(400+col with multi-level of nesting)
ID,
name: {first, last}
I want to view record particular user & display in my applicable, so my query is
SELECT * FROM dataset.user WHERE id=423421 limit 1
is it possible to return the result directly?
You should write your output to "temp" table with noflatten_results option (also respective expiration to be set to purge table after it is used) and serve your client out of this temp table. All "on-fly"
Have in mind that no matter how small "temp" table is - if you will be querying it (in above second step) you will be billed for at least 10MB, so you better use Tabledata.list API in this step (https://cloud.google.com/bigquery/docs/reference/v2/tabledata/list) which is free!
So if you try to get repeated records it will fail on the interface/BQ console with the error:
Error: Cannot output multiple independently repeated fields at the same time.
and in order to get past this error is to FLATTEN your output.

Implicit Fact division and Dimension Usage

I have a star schema with Implicit Fact division as shown in Figure 5 at http://www.information-management.com/infodirect/20020308/4858-1.html?pg=2.
My question is how do I set up the Dimension Usage? My first thought was to set up 3 Referenced Relationships (CustomerGroup to InvoiceItemFacts, GroupToCustomer to CustomerGroup, CustomerDimension to GroupToCustomer), but when I try this I get the message "A loop was found in the data source view at the 'dbo_CustomerGroup' table".
Update:
I have found that if I create a Regular Relationship between GroupToCustomer and InvoiceItemFacts (effectively by passing the CustomerGroup table because I already have the Customer Group Key) I can get some results. However, when I browse the cube and display the InvoiceItemFacts by Customer, the InvoiceItemFacts only display on the first Customer in the group.
GroupToCustomer looks to be a "Fact-less Fact Table", so you would create a measuregroup on that, doesn't need to be visible to the end users, then do a Many-Many join via that fact in the dimension usage tab.
It's a little complicated by the extra table in the way, but that should be the approach.

Check if a given DB object used in Oracle?

Hi does any one know how to check if a given DB object (Table/View/SP/Function) is used inside Oracle.
For example to check if the table "A" is used in any SP/Function or View definitions. I am trying to cleanup unused objects in the database.
I tried the query select * from all_source WHERE TEXT like '%A%' (A is the table name). Do you thing it is safe to assume it is not being used if it does not return any results?
From this ASKTOM question:
You'll have to enable auditing and then come back in 3 months to see.
We don't track this information by default -- also, even with auditing, it may be very
possible to have an object that is INDIRECTLY accessed (eg: via a foreign key for
example) that won't show up.
You can try USER_DEPENDENCIES but that won't tell you about objects referenced by code in
client apps or via dynamic sql
There's code in the thread for checking ALL_SOURCE, but it's highlighted that this isn't a silver bullet.