This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create and Insert query for testing Insert performance for table WITH primary keys | |
create table test_inserts_with_primary_key ( | |
id bigint not null auto_increment, | |
text_field_1 varchar(50), | |
text_field_2 varchar(50), | |
created_at date, | |
primary key (id) | |
) engine = innodb; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysqlslap --create-schema="tests" \ | |
--concurrency=4 \ | |
--query="insert into test_inserts_with_primary_key select null id, md5(rand()) text_field_1, md5(rand()) text_field_2, curdate() - interval round(rand() * 200) day created_at" \n | |
--number-of-queries=10000000 \ | |
--iterations=1 \ | |
-uroot -p | |
mysqlslap --create-schema="tests" \ | |
--concurrency=4 \ | |
--query="insert into test_inserts_with_primary_key select 10129 id, md5(rand()) text_field_1, md5(rand()) text_field_2, curdate() - interval round(rand() * 200) day created_at" \n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- when we want to keep only the first copy of a record by ID (where ID is integer). | |
-- Change min to max, when you want to keep the latest | |
DELETE FROM tab as t0 | |
WHERE t0.id <> (SELECT min(t1.id) FROM tab as t1 WHERE t0.id = t1.id); | |
-- when we want to identify distinct on the basis of selected columns, not the complete record | |
DELETE FROM tab t0 WHERE t0.id NOT IN | |
(SELECT t1.id FROM ( | |
SELECT DISTINCT ON (col_1, col_2, col_2, ..., col_n) * | |
FROM tab t1)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop function if exists transformation_utils.ts_to_seconds_of_day (p_timestamp timestamp); | |
create or replace function transformation_utils.ts_to_seconds_of_day (p_timestamp timestamp) | |
returns integer AS | |
$body$ | |
declare | |
hs integer; | |
ms integer; | |
s integer; | |
begin | |
select (extract (hour from p_timestamp::time) * 60 * 60) into hs; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop function if exists transformation_utils.ts_to_isodate (p_timestamp timestamp); | |
create or replace function transformation_utils.ts_to_isodate (p_timestamp timestamp) | |
returns integer AS | |
$body$ | |
declare | |
d integer; | |
begin | |
select to_char(p_timestamp::timestamp, 'YYYYMMDD') into d; | |
return d; | |
end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "pay_29QQoUBi66xm2f", | |
"entity": "payment", | |
"amount": 5000, | |
"currency": "INR", | |
"status": "captured", | |
"order_id": null, | |
"invoice_id": null, | |
"international": false, | |
"method": "wallet", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select * from json_to_record('{ | |
"id": "pay_29QQoUBi66xm2f", | |
"entity": "payment", | |
"amount": 5000, | |
"currency": "INR", | |
"status": "captured", | |
"order_id": null, | |
"invoice_id": null, | |
"international": false, | |
"method": "wallet", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop function if exists transformation_utils.remove_invalid_characters (p_string text); | |
create or replace function transformation_utils.remove_invalid_characters (p_string text) | |
returns text AS | |
$body$ | |
declare | |
c text; | |
begin | |
select replace(p_string,'�','') into c; | |
return c; | |
end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select edge_id, | |
(dp).path[1] As index, | |
ST_AsText((dp).geom) As wktnode | |
from (select 1 As edge_id, | |
ST_DumpPoints(ST_GeomFromText('LINESTRING(1 2, 3 4, 10 10)')) as dp | |
union all | |
select 2 As edge_id, | |
ST_DumpPoints(ST_GeomFromText('LINESTRING(3 5, 5 6, 9 10)')) as dp | |
) as foo; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table sal_emp ( | |
name text, | |
pay_by_quarter integer[], | |
schedule text[][] | |
); | |
insert into sal_emp | |
values ('Bill', | |
'{10000, 10000, 10000, 10000}', | |
'{{"meeting", "lunch"}, {"training", "presentation"}}'); |