Skip to content

Instantly share code, notes, and snippets.

@cjbj
cjbj / vector-query.py
Last active August 18, 2025 23:56
Querying an Oracle Database 23ai VECTOR column directly into a DataFrame using python-oracledb from the video "Python DataFrames with Oracle Database for Analysis and AI" https://youtu.be/lC07FNCzJ5w For other examples, see https://github.com/oracle/python-oracledb/tree/main/samples
# vector-query.py
#
# Run this after running vector-insert.py, https://gist.github.com/cjbj/ee7152b223928b5b7a5959fe87fa2ab3
#
# For other python-oracledb DataFrame examples, see https://github.com/oracle/python-oracledb/tree/main/samples
# Related blog: https://medium.com/oracledevs/the-best-way-to-fetch-and-insert-python-dataframes-and-tensors-with-oracle-database-70a1b24a3d99
# Documentation: https://python-oracledb.readthedocs.io/en/latest/user_guide/dataframes.html
import os
@cjbj
cjbj / vector-insert.py
Last active August 18, 2025 23:56
Inserting a DataFrame into a VECTOR column using python-oracledb from the video "Python DataFrames with Oracle Database for Analysis and AI" https://youtu.be/lC07FNCzJ5w For other examples, see https://github.com/oracle/python-oracledb/tree/main/samples
# vector-insert.py
#
# For other python-oracledb DataFrame examples, see https://github.com/oracle/python-oracledb/tree/main/samples
# Related blog: https://medium.com/oracledevs/the-best-way-to-fetch-and-insert-python-dataframes-and-tensors-with-oracle-database-70a1b24a3d99
# Documentation: https://python-oracledb.readthedocs.io/en/latest/user_guide/dataframes.html
import os
import pandas
import oracledb
@cjbj
cjbj / insert.py
Last active August 18, 2025 23:55
Inserting a DataFrame using python-oracledb from the video "Python DataFrames with Oracle Database for Analysis and AI" https://youtu.be/0BJNlbh71LY For other examples, see https://github.com/oracle/python-oracledb/tree/main/samples
# insert.py
#
# For other python-oracledb DataFrame examples, see https://github.com/oracle/python-oracledb/tree/main/samples
import os
import pandas
import oracledb
un = os.environ.get('ORACLE_USERNAME')
@cjbj
cjbj / deltalake-write.py
Last active August 18, 2025 23:54
Querying a DataFrame in batches and writing to Delta Lake using python-oracledb from the video "Python DataFrames with Oracle Database for Analysis and AI" https://youtu.be/0BJNlbh71LY For other examples, see https://github.com/oracle/python-oracledb/tree/main/samples
# deltalake-write.py
#
# For other python-oracledb DataFrame examples, see https://github.com/oracle/python-oracledb/tree/main/samples
import os
import oracledb
import pyarrow
from deltalake import DeltaTable, write_deltalake
@cjbj
cjbj / pandas-new.py
Last active August 18, 2025 23:53
Querying a DataFrame using python-oracledb from the video "Python DataFrames with Oracle Database for Analysis and AI" https://youtu.be/0BJNlbh71LY For other examples, see https://github.com/oracle/python-oracledb/tree/main/samples
# pandas-new.py
#
# For other python-oracledb DataFrame examples, see https://github.com/oracle/python-oracledb/tree/main/samples
import os
import pyarrow
import oracledb
un = os.environ.get('ORACLE_USERNAME')
@cjbj
cjbj / parallelselect.py
Last active February 14, 2023 23:02
A sample Python program that reads from an Oracle Database table in parallel threads
# parallelselect.py
#
# [email protected], Feb 2023
#
# This may or may not be faster than a single thread statement that
# reads the whole table.
#
import csv
import os
import getpass
import os
import traceback
import oracledb
un = ''
cs = ''
pw = getpass.getpass(f'Enter password for {un}: ')
try:
@cjbj
cjbj / dbora
Last active March 9, 2022 02:11
#! /bin/sh -x
#
# This is my old script for auto-starting Oracle DB on Linux.
# When I'm not using Cloud Databases, I now install the Oracle Database 21c RPM which includes its own script
#
# chkconfig: 2345 80 05
# description: start and stop Oracle Databases
#
# OL7: systemctl enable dbora
@cjbj
cjbj / issue1391.patch
Created July 21, 2021 23:42
Patch for node-oracledb 5.2 issue #1391
diff --git a/lib/queryStream.js b/lib/queryStream.js
index 08ddc72..09efc99 100644
--- a/lib/queryStream.js
+++ b/lib/queryStream.js
@@ -89,11 +89,6 @@ class QueryStream extends Readable {
this._fetching = true;
this._resultSet._allowGetRowCall = true;
const row = await this._resultSet.getRow();
- this._fetching = false;
- if (!this._resultSet) {
const oracledb = require('oracledb');
const dbConfig = require('./dbconfig.js');
if (process.platform === 'darwin') {
oracledb.initOracleClient({libDir: process.env.HOME + '/Downloads/instantclient_19_8'});
}
let result;
async function run() {