Is there any function avaliable in greenplum to generate UUID - greenplum

Is there any way to generate UUID in Greenplum. As latest version of Greenplum is using Postgres 8.2 and this feature is not available for Postgres 8.2 (used by Greenplum), but the same has been added to later versions of Postgres . Is there any way we can populate column with UUID in greenplum?

You could just write it in PL/Python, since Python's uuid library makes this easy (I'm assuming a random UUID, and that you can run this as "gpadmin"):
CREATE OR REPLACE FUNCTION UUID ()
RETURNS VARCHAR(36)
AS $$
import uuid
return str(uuid.uuid4())
$$ LANGUAGE plpythonu;
Now (still as gpadmin):
gpadmin=# select UUID() from generate_series(1, 10);
uuid
--------------------------------------
476f35e4-da1a-43cf-8f7c-950ac71d4848
71db22ed-ff6f-4615-a877-db803b474ae7
6584670a-ab4d-44c5-b854-7e19e66d4738
ed174b1f-0b61-48df-bdec-60146e063d74
bb643e3e-5d7f-4382-b415-0145cd2bca99
d4c784f7-1baa-4869-b9a8-d6cf6dce0cba
79e65c0f-9573-4d94-8c9a-f894ec096643
bf8dd0da-e1dd-4604-851d-01b0ac8793c3
b80180de-d342-456f-952f-1ca2cbcce4e4
f752ed61-d71a-4835-ac12-8e66132ba351
(10 rows)
Time: 1.902 ms

Related

how to run sql query on delta table

I have problem with delta lake docs. I know that I can query on delta table with presto,hive,spark sql and other tools but in delta's documents mentioned that "You can load a Delta table as a DataFrame by specifying a table name or a path"
but it isn't clear. how can I run sql query like that?
To read data from tables in DeltaLake it is possible to use Java API or Python without Apache Spark. See details at:
https://databricks.com/blog/2020/12/22/natively-query-your-delta-lake-with-scala-java-and-python.html
See how to use with Pandas:
pip3 install deltalake
python3
from deltalake import DeltaTable
table_path = "/opt/data/delta/my-table" # whatever table name and object store
# now using Pandas
df = DeltaTable(table_path).to_pandas()
df
Use the spark.sql() function
spark.sql("select * from delta.`hdfs://192.168.2.131:9000/Delta_Table/test001`").show()

Oracle UUID v3 or v5

Is it possible to create UUID v3 or v5 on the fly from selected data for getting UUID, which is made from the username and constant "Name space". I don't want to generate and save this data in the DB, only just get it on demand
For example something like this:
SELECT uuid('NAME SPACE', a.username) uuid
FROM USER_TABLE a
where a.username = 'username';
I'm using Oracle 19c
I'm pretty sure that in SQL itself Oracle only had the SYS_GUID and it is not v3 or v5. SYS_GUID is globally unique, but not compliant to RFC 4122.

MySQL 8 get PROCEDURE / FUNCTION full definition

I need to get the user defined PROCEDURE / FUNCTION full definition in MySQL 8.
MySQL 5.6 contain mysql.proc table there we can get the function full definition but MySQL 8 does not contain the proc table.
But MySQL 5.6 and 8 also have information_schema.ROUTINES table it contain only the function body,
I can not find functions parameter and return types.
what I did in MySQL 5.6
SELECT
`name` AS _schema,
CONVERT(body USING utf8) AS _schemaDef,
CONVERT(param_list USING utf8) AS param_list,
CONVERT(`returns` USING utf8) AS `returns`
FROM mysql.proc
WHERE db = 'my_db_name'
Any idea how to do this MySQL 8?
My ultimate target is copying all function and procedure from one DB to another DB by using PHP
I have find a solution that...
SHOW CREATE FUNCTION function_name
Above query work fine in MySQL 5.6 and 8.
But first I have to get list of FUNCTION names from information_schema.ROUTINES table and loop the record set, Inside the loop I have to run the above SHOW CREATE FUNCTION query.
How to Optimize this flow?

Loading configuration details from MySQL

I am trying to fetch the value from the database and want to load into my Go workspace, the data I am loading is a configuration data.
example - IP, log level, etc.
So when I run my Main Application, It should load those data from DB and should set somewhere, So that in my entire application I can use that.
DB looks something like this:
Parm_name | Param_val | param_id
IP |127.0.0.1 | 205
log level |2 | 206
I am using Mysql DB, But not getting how to set these values to a struct maybe and access throughout the application.
You can refer these code samples:
Using go sql driver
Playground link: https://play.golang.org/p/V9DWcBTJL9j
Using go sql driver with package sqlx
Playground link: https://play.golang.org/p/kXFIpjaX8-V
You can use sqlx package: https://github.com/jmoiron/sqlx.
It provides method for parsing data in struct with the help of field tags.
Refer this link for an illustrated guide: https://jmoiron.github.io/sqlx/
Run these query in MySQL for data setup:
create database stackoverflow;
use stackoverflow;
create table example(
Parm_name varchar(50) NOT NULL,
Param_val varchar(50) NOT NULL,
Param_id integer primary key
);
insert into example values('IP','127.0.0.1',205);
insert into example values('log level','2',206);

Pulling a timestamp across a database link from postgres to oracle

The company I work for is in the process of switching from oracle to EnterpriseDB and I'm trying to update a query that uses a timestamp from a table, but whenever I try to pull that timestamp it gives me:
[Devart][ODBC][PostgreSQL]Invalid TIMESTAMP string {HY000}
I've tried casting it as varchar2, date, timestamp, using to_date, and nothing has worked.
The query is:
select "ship_date" from "promotion"#pgProd
In postgres ship_date is just a timestamp.
Any information about how this can be accomplished would be appreciated.
EDIT: To clarify, this query is being run in oracle pulling data from postgres.
Oracle version is 11g
The relevent line of the creation script is:
ship_date timestamp without time zone NOT NULL

Resources