We'll reuse our module from the previous notebook (00_database_connectivity_setup.ipynb) to establish connectivity to the database
In [18]:
%run '00_database_connectivity_setup.ipynb'
IPython.display.clear_output()
Your connection object is conn:
psql.read_sql("""<YOUR SQL>""", conn). Alternatively, if you don't want a handle to the resulting dataframe, you can run the code inline using the magic command we defined in previously in cell: %%showsql.psql.execute("""<YOUR SQL>""", conn), followed by a conn.commit() command to ensure your transaction is committed. Otherwise your changes will be rolledback if you terminate your kernel. Alternatively, you could use the magic command that we previously defined in the cell: %%execsql.If you created a new connection object (say to connect to a new cluster) as shown in the last section of 00_database_connectivity_setup.ipynb notebook, use that connection object where needed.
In [19]:
%%execsql
drop table if exists gp_ds_sample_table;
create temp table gp_ds_sample_table
as
(
select
random() as x,
random() as y
from
generate_series(1, 10) x
) distributed randomly;
In [20]:
%%showsql
select
*
from
gp_ds_sample_table;