원클릭으로
postgresql
PostgreSQL database operations using PgQuery tool for DDL execution, schema management, and query operations
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
PostgreSQL database operations using PgQuery tool for DDL execution, schema management, and query operations
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
| name | PostgreSQL |
| description | PostgreSQL database operations using PgQuery tool for DDL execution, schema management, and query operations |
This skill covers PostgreSQL database operations using the PgQuery command-line tool for executing DDL scripts, managing schemas, and running queries against PostgreSQL databases.
When helping users with PostgreSQL operations, follow these guidelines:
Always Use PgQuery Tool: Use Y:/CSharpDLLs/PgQuery/PgQuery.exe for all PostgreSQL operations. Never use psql or other PostgreSQL clients directly.
Configuration Files: PostgreSQL connection details are stored in JSON configuration files (typically in R:/JsonParams/). Common configs:
x3rocs_db.json - x3rocs database connectiondw_db.json - Data warehouse connectionCommand Format: Use --config for database connection and either --file for SQL files or --sql for inline SQL:
Y:/CSharpDLLs/PgQuery/PgQuery.exe --config "<config-path>" --file "<sql-file-path>"
DDL Execution Order: When executing multiple DDL scripts that have dependencies:
Error Handling: Common PostgreSQL errors:
42501: must be owner of function - Shared function already exists, skip recreation42P01: relation does not exist - Table/view doesn't exist, check dependencies23503: foreign key violation - Referenced table missing or data constraint violatedSchema Organization: Follow the project's schema organization:
x3 schema - X3 integration data (customers, contacts, etc.)rocs schema - ROCS application data (price discounts, etc.)public schema - Shared utilities and functionsUser: Run the contact.sql DDL to create the new contact table
Claude: I'll execute the contact.sql DDL using PgQuery:
- Use the x3rocs database connection
- Execute the file from the Postgresql directory
- Handle any permission errors for shared functions
[Runs: Y:/CSharpDLLs/PgQuery/PgQuery.exe --config "R:/JsonParams/x3rocs_db.json" --file "c:/Users/matthew.heath/Git/RocsMiddleware/Postgresql/contact.sql"]
User: We need to update the customer and contact tables - contact has a foreign key to customer
Claude: I'll execute these in the correct order:
1. First run customer.sql (parent table)
2. Then run contact.sql (child table with foreign key)
3. Report any errors
[Executes customer.sql first, then contact.sql]
User: Check if the x3.contact table exists
Claude: I'll query the PostgreSQL information schema:
[Runs: Y:/CSharpDLLs/PgQuery/PgQuery.exe --config "R:/JsonParams/x3rocs_db.json" --sql "SELECT table_name FROM information_schema.tables WHERE table_schema = 'x3' AND table_name = 'contact'"]
User: Export the customer table to a parquet file
Claude: I'll export using the --parquet flag:
[Runs: Y:/CSharpDLLs/PgQuery/PgQuery.exe --config "R:/JsonParams/x3rocs_db.json" --sql "SELECT * FROM x3.customer" --parquet "C:/tmp/customers.parquet"]
Location: Y:/CSharpDLLs/PgQuery/PgQuery.exe or C:/Users/matthew.heath/Git/PgQuery
Purpose: Command-line tool for executing PostgreSQL queries and DDL scripts with JSON configuration support
# Execute SQL file
Y:/CSharpDLLs/PgQuery/PgQuery.exe --config "<config-file>" --file "<sql-file>"
# Execute inline SQL
Y:/CSharpDLLs/PgQuery/PgQuery.exe --config "<config-file>" --sql "<sql-statement>"
Parameters:
--config / -c (required): Path to PostgreSQL connection config JSON file--file / -f: Path to SQL file to execute--sql / -s: Inline SQL statement to execute--output / -o: Write text output to a file--parquet / -p: Write query results to a Parquet file (SELECT queries only)--file or --sql, not bothLocation: R:/JsonParams/*.json
{
"host": "rivsprod01",
"port": "5432",
"database": "x3rocs",
"username": "jordan",
"password": "your-password"
}
Pattern: Always create parent tables before child tables
-- Parent table (customer.sql)
DROP TABLE IF EXISTS x3.customer CASCADE;
CREATE TABLE x3.customer (
customer_code VARCHAR(30) PRIMARY KEY,
customer_name VARCHAR(50) NOT NULL,
-- ... other fields
);
-- Child table (contact.sql) - references parent
DROP TABLE IF EXISTS x3.contact CASCADE;
CREATE TABLE x3.contact (
customer_code VARCHAR(30) NOT NULL,
contact_code VARCHAR(15) NOT NULL,
-- ... other fields
PRIMARY KEY (customer_code, contact_code),
FOREIGN KEY (customer_code) REFERENCES x3.customer(customer_code) ON DELETE CASCADE
);
Execution Order:
customer.sql firstcontact.sql secondPattern: Use MD5 hash triggers for detecting data changes
-- Hash column in table
CREATE TABLE x3.customer (
customer_code VARCHAR(30) PRIMARY KEY,
-- ... data fields
x3_hash VARCHAR(32), -- MD5 hash for change detection
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);
-- Hash calculation function
CREATE OR REPLACE FUNCTION x3.update_customer_hash()
RETURNS TRIGGER AS $$
BEGIN
NEW.x3_hash := md5(
COALESCE(NEW.customer_code, '') || '|' ||
COALESCE(NEW.customer_name, '') || '|' ||
-- ... concatenate all fields for hashing
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Trigger to auto-calculate hash
CREATE TRIGGER trg_update_customer_x3hash
BEFORE INSERT OR UPDATE ON x3.customer
FOR EACH ROW
EXECUTE FUNCTION x3.update_customer_hash();
Key Points:
|| for string concatenation with pipe delimiterPattern: Stored procedures for INSERT ... ON CONFLICT DO UPDATE
CREATE OR REPLACE FUNCTION x3.upsert_contact(
p_customer_code VARCHAR(30),
p_contact_code VARCHAR(15),
p_title VARCHAR(20),
-- ... other parameters
)
RETURNS VOID AS $$
BEGIN
INSERT INTO x3.contact (
customer_code, contact_code, title, -- ...
) VALUES (
p_customer_code, p_contact_code, p_title, -- ...
)
ON CONFLICT (customer_code, contact_code)
DO UPDATE SET
title = EXCLUDED.title,
-- ... update all fields
END;
$$ LANGUAGE plpgsql;
Cause: Shared function already exists and is owned by another user
Solution: Skip recreating the shared function or comment it out in the DDL script
-- Comment out if function already exists
-- CREATE OR REPLACE FUNCTION x3.update_updated_column()
-- RETURNS TRIGGER AS $$
-- BEGIN
-- NEW.updated = CURRENT_TIMESTAMP;
-- RETURN NEW;
-- END;
-- $$ LANGUAGE 'plpgsql';
Cause: Referenced table doesn't exist yet
Solution: Execute DDL files in dependency order (parent tables first)
Cause: DROP TABLE ... CASCADE will drop dependent objects
Solution: This is expected behavior. The CASCADE keyword is intentional for clean rebuilds.
--file parameterDROP TABLE IF EXISTS x3.customer CASCADE ensures clean drops(customer_code, contact_code) for multi-column keysON DELETE CASCADE for parent-child relationshipsx3., rocs., etc.)updated column with BEFORE UPDATE triggersAnthropic API rate limit handling - retry logic, backoff, throttling for batch workloads against Claude models
Use when building an automated test → issue → fix loop with Claude Code and GitHub issues — overnight auto-fixing, regression loops, self-healing CI.
Use when creating, editing, publishing, or deleting posts on Cyril's Workshop blog or the steponnopets.net devblog.
Use when writing or contributing a boofuzz network-protocol fuzzer in this repo — layout, formatting rules, and reading results.
Use when a task needs real-time control of a connected browser via the Browser Bridge Broker — submit JS jobs over HTTP that browsers eval and return.
Use when training a character LoRA (Chroma/Flux or Pony/SDXL) on a RunPod GPU and wiring it into the ComfyUI + pony_web render stack.