Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I started creating a flask application as I will be needing to do some visualization of some data that was recently transferred to a local postgresql database.

I have a lot of tables (33) which all have the same kind of content as currently just works as containers for different types of data (They contain a JSON object that's different in each of the tables though).

The tables are named "Table_#" (where # symbolizes a number among a defined subset of numbers).

models.py

I have created the following model:

from sqlalchemy import BigInteger, Column, JSON, Text
from app import db

class Table_1(db.Model):
    __tablename__ = 'table_1'

    id = db.Column(BigInteger, primary_key=True)
    did = db.Column(Text)
    timestamp = db.Column(BigInteger)
    data = db.Column(JSON)
    db_timestamp = db.Column(BigInteger)

    def __repr__(self):
        return '<1_Data %r>' % (self.did)

to test if I can actually grab some data from my postgresql.

__init__.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)

from app import views, models

config.py

In my config.py I have the following:

SQLALCHEMY_DATABASE_URI = "postgresql://<username>:<password>@localhost:5432/backupdata" //Ofc <username> and <password> isn't my credentials..

In my terminal (Windows cmd) I've tried running the following:

>python
>>>from app import db, models
>>>row = models.Table_1.query.get(1)

But for some reason when I try to print my row nothing is output.

I was hoping someone could have an idea why that is?

share|improve this question
    
Do you have a record in the table with a primary key of 1? – dirn 2 days ago
    
Does the above command get the id's of the rows? I thought it was like just get 1 row.. But if it's the ID of the row then that is my problem. How would I got about getting a "random" row or a random subset of rows? – Zeliax 2 days ago
1  
    
Then I am definitively using the wrong command. Thanks for informing me. I will get right on checking the documentation ;) – Zeliax 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.