amazon-redshift

Redshift: Executing a dynamic query from a string

情到浓时终转凉″ 提交于 2019-12-18 05:54:07
问题 I would like to execute a dynamic SQL query stored in a string field on Amazon Redshift. My background is mostly T-SQL relational databases. I used to build SQL statements dynamically, store them into variables and them execute them. I know Redshift can prepare and execute statements, but I wonder if it is possible to execute a query stored in a string field. I have a piece of code that dynamically builds the code below with stats on several tables using pg_* system tables. Every column/table

Redshift. Convert comma delimited values into rows

依然范特西╮ 提交于 2019-12-17 09:21:14
问题 I am wondering how to convert comma-delimited values into rows in Redshift. I am afraid that my own solution isn't optimal. Please advise. I have table with one of the columns with coma-separated values. For example: I have: user_id|user_name|user_action ----------------------------- 1 | Shone | start,stop,cancell... I would like to see user_id|user_name|parsed_action ------------------------------- 1 | Shone | start 1 | Shone | stop 1 | Shone | cancell .... 回答1: A slight improvement over the

Redshift. Convert comma delimited values into rows

爱⌒轻易说出口 提交于 2019-12-17 09:21:08
问题 I am wondering how to convert comma-delimited values into rows in Redshift. I am afraid that my own solution isn't optimal. Please advise. I have table with one of the columns with coma-separated values. For example: I have: user_id|user_name|user_action ----------------------------- 1 | Shone | start,stop,cancell... I would like to see user_id|user_name|parsed_action ------------------------------- 1 | Shone | start 1 | Shone | stop 1 | Shone | cancell .... 回答1: A slight improvement over the

generate_series() method fails in Redshift

久未见 提交于 2019-12-17 05:11:36
问题 When I run the SQL Query: select generate_series(0,g) from ( select date(date1) - date(date2) as g from mytable ; It returns an error: INFO: Function "generate_series(integer,integer)" not supported. ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables. But when I run this query: select generate_series(0, g) from (select 5 as g) It returns the below response: generate_series ----------------- 0 1 2 3 4 5 (6 rows) Why does the second query work, while the

How do I keep more than 5 day's worth of query logs?

落花浮王杯 提交于 2019-12-14 04:17:18
问题 In Redshift, there's an STL_QUERY table that stores queries that were run over the last 5 days. I'm trying to find a way to keep more than 5 days worth of records. Here are some things that I've considered: Is there a Redshift setting for this? It would appear not. Could I use a trigger? Triggers are not available in Redshift, so this is a no-go. Could I create an Amazon Data Pipeline job to periodically "scrape" the STL_QUERY table? I could, so this is an option. Unfortunately, I would have

How do I count multiple columns of events for users?

偶尔善良 提交于 2019-12-14 03:35:52
问题 I have a table of events that stores the events for users and I want to get the number of two specific events for each user. An example table is called "events" and it has 2 columns user_id VARCHAR(50) event_name VARCHAR(50) The user_ids are all unique and the event names can be things like login, sent_message, liked_post How do I, for example, query for the total messages sent per user AND the number of liked_posts per user? 回答1: This is the pattern of query you can use: select user_id, sent

Configure AWS Redshift on Ubuntu 18.04 and use it with pyodbc

佐手、 提交于 2019-12-13 21:23:09
问题 When I try to connect to my DSN using pyodbc I am getting following error: python3: Relink /lib/x86_64-linux-gnu/libudev.so.1' with /lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime' Segmentation fault (core dumped) I have tried different solution like reinstalling libudev1 etc. but nothing is working. I tried to connect to using 16.04 VM and I am getting could not connect to server: Connection timed out Is the server running on host xxxxxx and accepting TCP/IP connections on

Issue with passing column name as a parameter to “PREPARE” in Redshift

不问归期 提交于 2019-12-13 20:10:30
问题 I am using REDSHIFT for the below question, Here is problem and I am looking for solution. I have 2 tables, one table contains the column combinations on which the second table should group the results by. Table 1 containing column combinations (This is output from a stored procedure): COMBINATIONS fruit_combinations banana,'ALL' banana, orange Table 2 containing fruit_baskets: FRUIT_BASKET BANANA ORANGE USER_COUNT b1 o1 5 b1 o2 10 Result set: FRUIT_BASKET_AGG BANANA ORANGE USER_COUNT b1 'ALL

SQL: Find longest common string between rows

♀尐吖头ヾ 提交于 2019-12-13 18:42:38
问题 I have a table T1: Col ------- 1 THE APPLE THE APPLE THE APPLE 123 THE APPLE 12/16 BEST THE APPLE I want T2: Result -------- THE APPLE I am using Redshift, Looking for some way to do a fuzzystring match in SQL. Longest length possible for column is 100 characters. At no point will I have to compare more than 25 rows. 回答1: This question requires a fair degree of complication to solve and it's running time will drastically increase with increasing string lengths and number of records. However,

Amazon AWS connection error

主宰稳场 提交于 2019-12-13 16:27:11
问题 I have just setup my first Redshift cluster and attempting to connect to it via SQL Workbench to be able to create tables. I have followed the directions for installing and configuring SQL Workbench here: http://docs.aws.amazon.com/redshift/latest/mgmt/connecting-using-workbench.html I have also downloaded and configured both the 4.0 and 4.1 version of the Redshift JDBC driver and attempted to use both. When I configure a connection using the JDBC URL provided in the cluster configuration,