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
update pg_catalog.pg_database set datistemplate = false where datname = 'template1'; | |
drop database template1; | |
create database template1 template template0 encoding 'utf8' lc_collate 'fr_FR.utf8' lc_ctype 'fr_FR.utf8'; | |
update pg_catalog.pg_database set datistemplate = true where datname = 'template1'; |
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
é é | |
è è | |
à Ã | |
ù ù | |
ç ç | |
î î | |
ô ô |
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
with | |
dup_id as (select id, count(*) from school group by id having count(*) > 1), | |
del_dup as (delete from only school using dup_id where school.id = dup_id.id returning school.*) | |
insert into school select distinct on (id) del_dup.* from del_dup order by del_dup.id returning *; |
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 or replace function restart_sequence(seq_name varchar) returns void language plpgsql as $func$ | |
declare | |
maxint bigint; | |
table_name varchar; | |
begin | |
table_name := left(seq_name, -7); | |
execute 'select max(id) + 1 from '||table_name into maxint; | |
if maxint is not null then | |
execute 'alter sequence '||seq_name||' restart with '||cast(maxint as text); | |
end if; |
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
#!/bin/bash | |
echo "Postgresql setup"; | |
echo -n "What is your Postgresql username [$USER]:> "; | |
read db_username; | |
echo -n "What is this user's password (empty if none) [] :> "; | |
read db_password; | |
echo -n "What is the server address (IP address or socket directory [localhost] :> "; | |
read db_host; | |
echo -n "What is the server port [5432] :> "; |
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
WITH | |
timerange (ts) AS (SELECT generate_series(date_trunc('hour', min(collected_at)), date_trunc('hour', max(collected_at)) + '1 day'::interval, '1 hour'::interval) FROM statistic) | |
SELECT | |
ts, | |
count(stat), | |
stddev(stat), | |
avg(stat) | |
FROM | |
timerange t | |
LEFT JOIN statistic s ON s.collected_at <@ tsrange(t.ts, t.ts + '1 hour'::interval, '[)') |
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 USER backup_user WITH ENCRYPTED PASSWORD 'password'; | |
GRANT CONNECT ON DATABASE production to backup_user; | |
\c production | |
GRANT USAGE ON SCHEMA public to backup_user; /*thanks Dominic!*/ | |
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO backup_user; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO backup_user; |
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
db.collection.find({"changes.objectSid": { $exists: 1}, "changes.pwdLastSet": { $exists: 1 }}).forEach(function(doc) { | |
var other_found = false; | |
for (key in doc.changes) { | |
if (key != 'objectSid' && key != 'pwdLastSet') { |
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
<?php | |
namespace My\Database\Type; | |
use \Pomm\Type\Composite; | |
class Address extends Composite | |
{ | |
public $place; | |
public $postal_code; |
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
<?php // CustomerMap.php | |
// ... | |
public function findAllWithOrderCount() | |
{ | |
return $this->queryWithOrderCount(new Where()); | |
// SELECT ... WHERE true; | |
} | |