I am running the streamlit locally and trying to interact with postgres.
I am running into a problem.
I have a requirement to insert the record in the DB and fetch it back.
But for the inserted records I am not getting back the record after executing the select query. There are no errors reported and I can see the record in DB.
Code to insert data:
def savePublisher(publisher):
with conn.session as session:
session.execute(
text("insert into publisher (publisher_name) values (:publisher)"), {"publisher": publisher}
)
session.commit()
Code to select data:
def getPublisher(publisher):
df = conn.query(
"select * from public.publisher where publisher_name = '" + publisher + "'",
)
return df
Import statement and create connection
import streamlit as st
from sqlalchemy import text
conn = st.connection("postgres", type="sql", autocommit=True)
Secret.toml
[connections.postgres]
dialect = "postgresql"
host = "localhost"
port = 5432
dbname = "bookleader"
username = "bookleader"
password = "bookleader"
Please help me resolving this issue.