Skip to content

Instantly share code, notes, and snippets.

PostgreSQL: reordering columns in migrations

PostgreSQL cannot change column position. There is no AFTER, BEFORE, FIRST, or ALTER COLUMN ... POSITION. Those are MySQL. ADD COLUMN always appends. REPACK and CLUSTER reorder rows, not columns. Do not rotate columns by adding new ones, copying values, and dropping the old ones. That burns attnum and often changes the type.

Reorder only when explicitly asked. Never tidy column order as a side effect. Never edit a migration that has already been applied. If the CREATE TABLE file has never been applied anywhere, change the column order in that file and stop. No table swap.

Target order

id is always the first column. Do not move it to suit alignment. If the table has no id, do not invent one and do not pull another column to the front.

@odan
odan / _vscode.md
Last active June 4, 2026 07:41
VSCode Setup
@odan
odan / HttpTest.cs
Created September 6, 2025 13:09
C# HTTP test with Json
using System.Text.Json.Nodes;
using System.Xml.Linq;
namespace Test.TestCase;
public class HttpTest
{
private ApplicationFactory _factory { get; set; }
private ClientAuth _clientAuth { get; set; }
@odan
odan / composer-branch.md
Created September 20, 2024 18:25
Require dev branch in PHP with composer

Using a specific branch instead of a version with composer

Example: Branch name is 5.x

{
    "repositories": [
        {
            "type": "git",
 "url": "https://github.com/odan/Slim.git"
@odan
odan / mssql-schema-dump.md
Last active November 25, 2024 02:09
Automate Your Database Schema Scripting with C# and SMO

Exporting SQL Server database structure into SQL script files

Scripting your SQL Server database schema is one such task that can benefit significantly from automation. Using C# and SQL Server Management Objects (SMO), you can easily generate scripts for your database schema and data.

Automating database scripting ensures that your schema and data scripts are always up-to-date and reduces the risk of human error. It is particularly useful for version control, backups, and migration tasks.

By integrating it into your workflow, you can significantly enhance your database management processes.

using System;
using System.Collections.Generic;
using System.Globalization;
// CultureInfo culture = new CultureInfo("en-US");
// Full-date notation as defined by RFC 3339, section 5.6, for example, 2024-03-28
string date1 = string.Format("{0:yyyy}-{0:MM}-{0:dd}", DateTime.Now);
Console.WriteLine(date1);

Convert video to a Twitter-friendly format

Simple, but with minimum modification:

ffmpeg -i "input.mp4" -pix_fmt yuv420p -vcodec libx264 "output.mp4"

Resizes the video and may better support encodings:

File Operations in C++

Reading a file into a string variable

#include <iostream>
#include <fstream>
using namespace std;

fstream file("file.name.xml", fstream::in);