Show ROLES provide me the info about Roles and user to whom the roles are assigned to.
However instead of providing the username it gives the user number like below in assigned_to_users
show roles;
---------------------------------+---------------+------------+------------+--------------+-------------------+------------------+---------------+---------------+--------------------------+
created_on | name | is_default | is_current | is_inherited | assigned_to_users | granted_to_roles | granted_roles | owner | comment |
---------------------------------+---------------+------------+------------+--------------+-------------------+------------------+---------------+---------------+--------------------------+
Fri, 05 Dec 2014 16:25:06 -0800 | ACCOUNTADMIN | Y | Y | N | 1 | 0 | 2 | | |
Mon, 15 Dec 2014 17:58:33 -0800 | ANALYST | N | N | N | 0 | 6 | 0 | SECURITYADMIN | Data analyst |
Fri, 05 Dec 2014 16:25:06 -0800 | PUBLIC | N | N | Y | 0 | 0 | 0 | | |
Fri, 05 Dec 2014 16:25:06 -0800 | SECURITYADMIN | N | N | Y | 0 | 1 | 0 | | |
Fri, 05 Dec 2014 16:25:06 -0800 | SYSADMIN | N | N | Y | 5 | 1 | 2 | | |
---------------------------------+---------------+------------+------------+--------------+-------------------+------------------+---------------+---------------+--------------------------+
is there a way I can join the number to actual user.
SHOW USERS is show you the count of users it is assigned to:
SHOW USERS;
created_on
name
is_default
is_current
is_inherited
assigned_to_users
granted_to_roles
granted_roles
2022-03-06
USERADMIN
N
N
Y
0
1
0
create user testo;
grant role useradmin to user testo;
SHOW USERS;
created_on
name
is_default
is_current
is_inherited
assigned_to_users
granted_to_roles
granted_roles
2022-03-06
USERADMIN
N
N
Y
1
1
0
You might want the SHOW GRANTS command, in the show grants of role <role_name>; form? But that will require multiple requests to see all GRANTS of ALL roles to all users.
OR on a per database level information_schema.APPLICABLE_ROLES:
SELECT * FROM information_schema.APPLICABLE_ROLES;
GRANTEE
ROLE_NAME
ROLE_OWNER
IS_GRANTABLE
SIMEON
ACCOUNTADMIN
NO
SIMEON
ORGADMIN
NO
SIMEON
PUBLIC
NO
ACCOUNTADMIN
SECURITYADMIN
NO
ACCOUNTADMIN
SYSADMIN
NO
SECURITYADMIN
USERADMIN
NO
GRANTS_TO_ROLES View holds the privileges granted to roles.
GRANTS_TO_USERS View holds the roles granted to the users.
You can join them as follows to get what you're looking for:
select u.grantee_name
, u.role
, r.privilege
, r.granted_on
, r.name
from snowflake.account_usage.grants_to_users u
join snowflake.account_usage.grants_to_roles r
on u.role = r.grantee_name
where u.grantee_name = '<user_name>'
order by 1,2,3,4,5;
Related
I have a table with columns as follows:
+-----------+--------------------+---------------+-------------+
| person_id | appointment_status | starting_date | ending_date |
+-----------+--------------------+---------------+-------------+
| 1 | P | 2011-11-23 | 2012-11-23 |
+-----------+--------------------+---------------+-------------+
| 2 | JO | 2011-11-23 | 2012-11-23 |
+-----------+--------------------+---------------+-------------+
Based on the table, I wanted to output the total number of the person registered in a certain year group by their status. Basically something like this:
+-----------+---------------+------+
| Status | No. of Person | Year |
+-----------+---------------+------+
| Permanent | 5 | 2011 |
+-----------+---------------+------+
| Job Order | 16 | 2011 |
+-----------+---------------+------+
| Permanent | 10 | 2012 |
+-----------+---------------+------+
| Job Order | 19 | 2012 |
+-----------+---------------+------+
Assuming that in the year 2011, there are about 5 registered persons(employees) who are permanent and 16 on job orders. Then following year 2012, there are 10 permanent and 19 job orders.
Try this:
SELECT CASE appointment_status
WHEN 'P' THEN 'Permanent '
WHEN 'JO' THEN 'Job Order'
END AS [Status]
,COUNT(person_id) AS [No. of Person]
,YEAR(starting_date) AS [Year]
FROM [my_table]
GROUP BY CASE appointment_status
WHEN 'P' THEN 'Permanent '
WHEN 'JO' THEN 'Job Order'
END
,YEAR(starting_date);
I'm following the guide: Installing and Configuring the Kafka Connector
Snowflake Sink cannot be created with error: snowflake.database.name database does not exit
A bit of investigation and kafka_connector user cannot see the database from the showsql console:
kafka_connector_user_2#(no warehouse)#(no database).(no schema)>SHOW DATABASES like 'kafka%';
+------------+------+------------+------------+--------+-------+---------+---------+----------------+
| created_on | name | is_default | is_current | origin | owner | comment | options | retention_time |
|------------+------+------------+------------+--------+-------+---------+---------+----------------|
+------------+------+------------+------------+--------+-------+---------+---------+----------------+
0 Row(s) produced.
From sysadmin account:
Database
SHOW DATABASES like 'kafka%';
+-------------------------------+----------+------------+------------+--------+----------+---------+---------+----------------+
| created_on | name | is_default | is_current | origin | owner | comment | options | retention_time |
|-------------------------------+----------+------------+------------+--------+----------+---------+---------+----------------|
| 2020-06-24 05:02:47.370 -0700 | KAFKA_DB | N | N | | SYSADMIN | | | 1 |
+-------------------------------+----------+------------+------------+--------+----------+---------+---------+----------------+
DB grants:
>SHOW GRANTS on database KAFKA_DB;
+-------------------------------+-----------------+------------+----------+------------+------------------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+-----------------+------------+----------+------------+------------------------+--------------+------------|
| 2020-06-26 01:11:22.082 -0700 | CREATE SCHEMA | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:11:22.082 -0700 | MODIFY | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:11:22.082 -0700 | MONITOR | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:11:22.082 -0700 | REFERENCE_USAGE | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:11:22.082 -0700 | USAGE | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-24 05:02:47.167 -0700 | OWNERSHIP | DATABASE | KAFKA_DB | ROLE | SYSADMIN | true | SYSADMIN |
+-------------------------------+-----------------+------------+----------+------------+------------------------+--------------+------------+
Role - User:
>SHOW GRANTS to user KAFKA_CONNECTOR_USER_2;
+-------------------------------+------------------------+------------+------------------------+---------------+
| created_on | role | granted_to | grantee_name | granted_by |
|-------------------------------+------------------------+------------+------------------------+---------------|
| 2020-06-26 01:04:59.699 -0700 | KAFKA_CONNECTOR_ROLE_1 | USER | KAFKA_CONNECTOR_USER_2 | SECURITYADMIN |
+-------------------------------+------------------------+------------+------------------------+---------------+
Role grants:
SHOW GRANTS to role KAFKA_CONNECTOR_ROLE_1;
+-------------------------------+--------------------------+------------+-----------------------+------------+------------------------+--------------+------------+
| created_on | privilege | granted_on | name | granted_to | grantee_name | grant_option | granted_by |
|-------------------------------+--------------------------+------------+-----------------------+------------+------------------------+--------------+------------|
| 2020-06-26 01:11:22.082 -0700 | CREATE SCHEMA | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:11:22.082 -0700 | MODIFY | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:11:22.082 -0700 | MONITOR | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:11:22.082 -0700 | REFERENCE_USAGE | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:11:22.082 -0700 | USAGE | DATABASE | KAFKA_DB | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-25 10:49:19.359 -0700 | CREATE PIPE | SCHEMA | KAFKA_DB.KAFKA_SCHEMA | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-25 10:49:18.358 -0700 | CREATE STAGE | SCHEMA | KAFKA_DB.KAFKA_SCHEMA | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-25 10:49:16.356 -0700 | CREATE TABLE | SCHEMA | KAFKA_DB.KAFKA_SCHEMA | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-25 10:49:14.354 -0700 | USAGE | SCHEMA | KAFKA_DB.KAFKA_SCHEMA | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
| 2020-06-26 01:16:36.396 -0700 | OPERATE | WAREHOUSE | COMPUTE_WH | ROLE | KAFKA_CONNECTOR_ROLE_1 | false | SYSADMIN |
+-------------------------------+--------------------------+------------+-----------------------+------------+------------------------+--------------+------------+
What am I missing ?
It looks like your "context" isn't set for that session, where context includes "current":
role
warehouse
database and schema
I'd recommend reviewing your connection properties, as well as executing the following and trying again:
ALTER USER kafka_connector_user_2 SET DEFAULT_ROLE = 'KAFKA_CONNECTOR_ROLE_1';
ALTER USER kafka_connector_user_2 SET DEFAULT_WAREHOUSE = 'COMPUTE_WH' ;
ALTER USER kafka_connector_user_2 SET DEFAULT_NAMESPACE = 'KAFKA_DB.KAFKA_SCHEMA' ;
https://docs.snowflake.com/en/sql-reference/sql/alter-user.html
Setting the user's default context is something I recommend for all "programatic" users (a.k.a. "Service Accounts").
I hope this helps...Rich
I need find the number of days between status change in SQL Server 2014.
For example, please see the data below
+--------+--------+------------+-------------+
| status | Number | updated_on | opened_at |
+--------+--------+------------+-------------+
| Draft | 100 | 2017-11-03 | 2017-11-03 |
| Draft | 100 | 2017-12-12 | 2017-11-03 |
| WIP | 100 | 2017-12-12 | 2017-11-03 |
| Appr | 100 | 2018-01-05 | 2017-11-03 |
| Launch | 100 | 2018-01-10 | 2017-11-03 |
| Close | 100 | 2018-01-11 | 2017-11-03 |
+--------+--------+------------+-------------+
Based on the above input, I need to get
Draft --- 40 days,
WIP --- 23 days,
appro -- 5 days,
deploy/launch - 1 days,
closed --- 69 days
Please help me with SQL query to arrive this results.
Thanks.
I don't think your numbers are right. But this should do what you want, assuming that the statuses are unique:
select status,
datediff(day, updated_on, lead(updated_on) over (order by updated_on) ) as days
from t;
I don't understand the first and last numbers, though.
Try this
SELECT
tb.status,
DATEDIFF(dayofyear, tb.opened_at, tb.LastUpdate) AS DaysInDifference
FROM
(
SELECT
DISTINCT
status,
Max(updated_on) OVER(PARTITION BY [status] )LastUpdate,
opened_at
FROM Table1
)AS tb
Is there any way to return the client IP address in Netezza? In Oracle we run below query .
SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual;
Thanks
This query can get you all the information you need about the current_session.
select client_ip
from _v_session_detail
where session_id= CURRENT_SID
You can use "show session" to provide that information if you aren't trying to access it as a column in a table.
SYSTEM.ADMIN(ADMIN)=> SYSTEM.ADMIN(ADMIN)=> show session;
SESSION_ID | PID | USERNAME | DBNAME | SCHEMA | TYPE | CONNECT_TIME | SESSION_STATE_NAME | SQLTEXT | PRIORITY_NAME | CLIENT_PID | CLIENT_IP | CLIENT_OS_USERNAME
------------+-------+----------+--------+--------+------+---------------------+--------------------+--------------+---------------+------------+-----------+--------------------
16228 | 10272 | ADMIN | SYSTEM | ADMIN | sql | 2014-12-10 10:56:48 | active | show session | normal | 10271 | 127.0.0.1 |
(1 row)
You can also query against the _v_session, which will report on sessions you have visibility/authorization to see, but doesn't necessarily tell you which one is yours. For a non-administrative user this is usually only your sessions, so it should be easy to tell.
SYSTEM.ADMIN(ADMIN)=> select * from _v_session;
ID | PID | USERNAME | DBNAME | TYPE | CONNTIME | STATUS | COMMAND | PRIORITY | CID | IPADDR | CLIENT_OS_USERNAME
-------+-------+----------+--------+------+---------------------+--------+--------------------------+----------+-------+-----------+--------------------
16228 | 10272 | ADMIN | SYSTEM | sql | 2014-12-10 10:56:48 | active | select * from _v_session | 3 | 10271 | 127.0.0.1 |
(1 row)
If you want information only about the particular session in which you are calling the query, then this will do the trick.
SYSTEM.ADMIN(ADMIN)=> select * from _v_session where id = current_sid;
ID | PID | USERNAME | DBNAME | TYPE | CONNTIME | STATUS | COMMAND | PRIORITY | CID | IPADDR | CLIENT_OS_USERNAME
-------+-------+----------+--------+------+---------------------+--------+-------------------------------------------------+----------+-------+-----------+--------------------
16837 | 22310 | ADMIN | SYSTEM | sql | 2014-12-10 19:06:21 | active | select * from _v_session where id = current_sid | 3 | 22309 | 127.0.0.1 |
(1 row)
I should note that what you're looking for here is already being tracked by the query history database, which is most likely already configured on your system.
I need help refining the WHERE clause on a query for the table below:
Key | Name | Role | Location
111 | Bob | Manager | All Locations
222 | Jim | Manager | All Locations
333 | Tim | Sales | Washington
444 | Roy | Sales | New York
555 | Lee | Sales | All Locations
666 | Gus | Sales | All Locations
777 | Joe | Admin | All Locations
888 | Jen | Admin | New York
I need to exclude all the 'All Locations' records, but keep the 'All Locations' records where the Role is Manager. To get the desired result:
Key | Name | Role | Location
111 | Bob | Manager | All Locations
222 | Jim | Manager | All Locations
333 | Tim | Sales | Washington
444 | Roy | Sales | New York
888 | Jen | Admin | New York
I feel that the query below would exclude all the All Locations records, including the Manager ones.
SELECT * FROM Table
WHERE (Location <> 'All Locations' AND Role <> 'Manager')
You will want to expand the WHERE:
select *
from yourtable
where
(
role = 'Manager'
and location = 'All Locations'
)
or
(
location <> 'All Locations'
)
See SQL Fiddle with Demo
Returns the result:
| KEY | NAME | ROLE | LOCATION |
----------------------------------------
| 111 | Bob | Manager | All Locations |
| 222 | Jim | Manager | All Locations |
| 333 | Tim | Sales | Washington |
| 444 | Roy | Sales | New York |
| 888 | Jen | Admin | New York |
SELECT * FROM Table
WHERE (Location != 'All Locations' OR (Location = 'All Locations' AND Role = 'Manager')
You say "exclude all the 'All Locations' records, but keep the 'All Locations' records where the Role is Manager." Doesn't that mean exclude the All location records where role is not manager? i.e., don't you want records 111 and 222 to be included ??
From De Morgans Law, Not A And Not B is equivalent to Not (A Or B)
In your case , one predicate is positive and the other negative, so De Morgan would read:
Not (A And not B) <=> (Not A or B), i.e.,
That means include all records that are either Not All Locations or Manager .
If so then what you need is:
... Where Location != 'All Locations' Or Role = 'Manager'
You should use OR instead of AND
SELECT * FROM Table
WHERE (Location <> 'All Locations' OR Role = 'Manager')