Skip to content

Instantly share code, notes, and snippets.

@luza
luza / snippet.sql
Last active September 19, 2023 09:42
Move table and all the attached indices to a new tablespace
-- Define the new tablespace name and the target table name
DO $$
DECLARE
new_tablespace TEXT := 'new_tablespace_name';
target_table TEXT := 'your_table_name'; -- Replace with the table name you want to move
BEGIN
-- Create a temporary table to store index names
CREATE TEMP TABLE temp_indexes AS
SELECT indexname
FROM pg_indexes
// instrumentedWriter is a wrapper around gin.ResponseWriter that calls
// BeforeWriteHeaderCallback before response headers is written.
type instrumentedWriter struct {
gin.ResponseWriter
BeforeWriteHeaderCallback func()
}
func (w *instrumentedWriter) Write(data []byte) (int, error) {
w.runBeforeWriteHeaderCallbackOnce()
return w.ResponseWriter.Write(data)
<?php
namespace AppBundle\Doctrine;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDOPgSql\Driver as PDOPgSqlDriver;
use Doctrine\ORM\NativeQuery;
class PgSqlNativeQueryCursor
{
@luza
luza / main.go
Last active August 6, 2019 14:42
First untested(!) implementation of traffic-lights-demo
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
@luza
luza / ean13_generator.sql
Last active May 26, 2018 10:52
EAN13 barcode generator example plpgsql postgres
with recursive source as (
select (220000000000::bigint + round(random() * 10000000000))::bigint as code
from generate_series(1, 10000)
),
checksum_calc as (
select code, 3 as cs_mult, 0::bigint as checksum, code as interm_code from source
union
select
code,
(case when cs_mult = 3 then 1 else 3 end) as cs_mult,