Skip to content

Commit

Permalink
chore: update psql samples
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed May 28, 2024
1 parent 1e2e32d commit 7cf8e33
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 48 deletions.
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/add_column.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

psql -c "ALTER TABLE albums ADD COLUMN marketing_budget bigint"
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/create_connection.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Set the connection variables for psql.
# The following statements use the existing value of the variable if it has
# already been set, and otherwise assigns a default value.
PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Connect to Cloud Spanner using psql through PGAdapter
# and execute a simple query.
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/create_tables.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Set the connection variables for psql.
# The following statements use the existing value of the variable if it has
# already been set, and otherwise assigns a default value.
PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Create two tables in one batch.
psql << SQL
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/data_boost.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# 'set spanner.data_boost_enabled=true' enables Data Boost for
# all partitioned queries on this connection.
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/ddl_batch.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Use a single SQL command to batch multiple statements together.
# Executing multiple DDL statements as one batch is more efficient
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/partitioned_dml.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Change the DML mode that is used by this connection to Partitioned
# DML. Partitioned DML is designed for bulk updates and deletes.
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/query_data.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

psql -c "SELECT singer_id, album_id, album_title
FROM albums"
9 changes: 9 additions & 0 deletions samples/snippets/psql-snippets/query_data_with_new_column.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

psql -c "SELECT singer_id, album_id, marketing_budget
FROM albums
ORDER BY singer_id, album_id"
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/query_data_with_parameter.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Create a prepared statement to use a query parameter.
# Using a prepared statement for executing the same SQL string multiple
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/read_only_transaction.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

psql << SQL
-- Begin a transaction.
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/statement_timeout.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Set the statement timeout that should be used for all statements
# on this connection to 5 seconds.
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/tags.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

psql << SQL
-- Start a transaction.
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/update_data_with_copy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Instruct PGAdapter to use insert-or-update for COPY statements.
# This enables us to use COPY to update data.
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/update_data_with_transaction.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

psql << SQL
-- Transfer marketing budget from one album to another.
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/write_data_with_copy.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Get the source directory of this script.
directory=${BASH_SOURCE%/*}/

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Copy data to Spanner from a tab-separated text file using the COPY command.
psql -c "COPY singers (singer_id, first_name, last_name) FROM STDIN" \
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/write_data_with_dml.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

psql -c "INSERT INTO singers (singer_id, first_name, last_name) VALUES
(12, 'Melissa', 'Garcia'),
Expand Down
6 changes: 3 additions & 3 deletions samples/snippets/psql-snippets/write_data_with_dml_batch.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

PGHOST="${PGHOST:-localhost}"
PGPORT="${PGPORT:-5432}"
PGDATABASE="${PGDATABASE:-example-db}"
export PGHOST="${PGHOST:-localhost}"
export PGPORT="${PGPORT:-5432}"
export PGDATABASE="${PGDATABASE:-example-db}"

# Create a prepared insert statement and execute this prepared
# insert statement three times in one SQL string. The single
Expand Down

0 comments on commit 7cf8e33

Please sign in to comment.