Re: [sqlalchemy] Re: Connection error

2021-06-16 Thread Rich Shepard
On Wed, 16 Jun 2021, Ryan Bandler wrote: Yeah I connect to the DB over localhost:5432 via psql all the time and also haven't had any issues connecting via psycopg2. I also have no issue connecting to the database in sqlalchem, it's only an issue with sqlacodegen. Ryan, Just to confirm,

Re: [sqlalchemy] Connection error

2021-06-15 Thread Rich Shepard
On Tue, 15 Jun 2021, Ryan Bandler wrote: I am a first-time SQLalchemy user planning on using SQLalchemy on a new project. Ryan, I started to learn SA long ago, but put off the project. Now I'm starting over again with much to learn. We already have an established postgres database

[sqlalchemy] checking in

2021-06-14 Thread Rich Shepard
I've not worked with SQLAlchemy for several years but now want to use it in a couple of applications. I've not seen messages on this maillist for a very long time so I tried subscribing and learned that I'm still subscribed. Am I the only one on this list now? If not I wonder why messages

[sqlalchemy] Not receiving messages posted to the group

2021-01-13 Thread Rich Shepard
I'm subscribed to the group but do not receive email copies of posted messages. I've looked on the forum's web page and did not see where to turn on email participation. Please point me to where I can control receiving/posting messages via email. TIA, Rich -- SQLAlchemy - The Python SQL

[sqlalchemy] Defining model.py for existing database

2020-12-18 Thread Rich Shepard
I'm working on learning SQLAlchemy to use for my business tracking application. I have the views written (in tkinter) and two versions of model.py as the model. Long ago I asked about using base or declarative base but no longer have that thread saved. I've read about base mapping and

Re: [sqlalchemy] Re: AM/PM question [ANSWERED]

2020-03-20 Thread Rich Shepard
On Fri, 20 Mar 2020, Jonathan Vanasco wrote: It doesn't matter when the time is entered or what it is supposed to reflect. The best option -- by a wide margin -- for storing any time values is in a TIMESTAMP column ... Jonathan, Thanks. I've not before needed this information and I

Re: [sqlalchemy] Re: AM/PM question

2020-03-20 Thread Rich Shepard
On Fri, 20 Mar 2020, Jonathan Vanasco wrote: The common approach to this situation is storing the data as a 24hour timestamp in the database/sqlalchemy and converting it to a 12hour am/pm for display/editing. You could use a "12 hour" option and an enum column for am/pm or a string. You're

[sqlalchemy] AM/PM question

2020-03-20 Thread Rich Shepard
A couple of sqlalchemy classes need to store user-entered times. The intended user audience is probably unfamiliar with using a 24-hour clock so I'll use the ttk.Radiobutton to have the user select AM or PM for the period. How do I represent this variable in the class definition of columns? The

Re: [sqlalchemy] Re: Composite key; one field is also foreign key [RESOLVED]

2019-06-18 Thread Rich Shepard
On Tue, 18 Jun 2019, Jonathan Vanasco wrote: adding `primary_key=True` to each of the `Column` constructors should do it. Thanks, Jonathan. Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE:

[sqlalchemy] Composite key; one field is also foreign key

2019-06-18 Thread Rich Shepard
I understand that multiple fields in a declarative base class can be specified as a composite primary key. In my application rather than using a unique, serialized primary key for each table/field I use a foreign key reference to a row in the locations table and a date. For example, site_name =

Re: [sqlalchemy] Importing module from another subdirectory [UPDATE 2]

2019-04-17 Thread Rich Shepard
On Wed, 17 Apr 2019, Rich Shepard wrote: Getting closer. Added a blank __init.py__ in the models/ subdirectory. Now I'm looking for the proper syntax to import the relevant class within that module. So more work on my part. I'm moving this thread to the python mail list; it's a python

Re: [sqlalchemy] Importing module from another subdirectory [UPDATE]

2019-04-17 Thread Rich Shepard
On Wed, 17 Apr 2019, Rich Shepard wrote: What is the proper syntax to import models as m a in a view module, e.g., activities.py? The syntax, 'import model as m' fails because it is not in the same subdirectory as the importing module. Getting closer. Added a blank __init.py__ in the models

[sqlalchemy] Tkinter search dialog box for model row

2019-04-17 Thread Rich Shepard
My web search for an existing Tkinter search dialog box found nothing. I'm looking for a pointer to a module or method if one exists. In this application the user needs to find database rows based on two class columns: lname and fname and display results in the appropriate data entry dialog

[sqlalchemy] Importing module from another subdirectory

2019-04-17 Thread Rich Shepard
My application intends to follow the MVC pattern. The model.py module is ../model/model.py while the Tkinter views are in ../views/. Both are relative to the application's main directory: bustrac/ README.rst bustrac.py* controller/ images/ model/ scripts/ views/ What is the

Re: [sqlalchemy] Re: Documentation options

2019-03-29 Thread Rich Shepard
On Sat, 30 Mar 2019, Cameron Simpson wrote: If it is of use I have this shell function: open_dash () { open "dash://$*" } and this alias: alias //=open_dash so that I can go "// search terms here" from the shell command line. Avoids some painful touchpad/mouse mucking around.

Re: [sqlalchemy] Re: Documentation options

2019-03-29 Thread Rich Shepard
On Fri, 29 Mar 2019, Rich Shepard wrote: This looks like the ideal solution. I'll install Dash and use it. Actually, I won't because it's an Apple product for their macOS and iOS. However, slackbuilds.org has a package called Zeal (a simple offline documentation browser inspired by Dash

Re: [sqlalchemy] Documentation options

2019-03-29 Thread Rich Shepard
On Fri, 29 Mar 2019, Mike Bayer wrote: I'd prefer any code samples are shared on-list here for the benefit of all to see, thanks. Mike, I was unsure about the proper protocol. I'll post the module here Real Soon Now. Thanks, Rich -- SQLAlchemy - The Python SQL Toolkit and Object

Re: [sqlalchemy] Re: Documentation options

2019-03-29 Thread Rich Shepard
On Fri, 29 Mar 2019, Xavier Bustamante Talavera wrote: I use Dash to read SQLAlchemy documentation, which is great to search through it and works offline (it downloads the whole docs). Xavier, This looks like the ideal solution. I'll install Dash and use it. Many

Re: [sqlalchemy] Documentation options

2019-03-26 Thread Rich Shepard
On Thu, 21 Mar 2019, Mike Bayer wrote: sounds like automap: https://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html Mike, May I send you models.py (off the mail list) to check that I have correctly applied automap? TIA, Rich -- SQLAlchemy - The Python SQL Toolkit and Object

Re: [sqlalchemy] Documentation options

2019-03-21 Thread Rich Shepard
On Thu, 21 Mar 2019, Mike Bayer wrote: sounds like automap: https://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html Mike, While this does not look familiar, I'll carefully read the page again until I really understand it. Now, model.py contains classes for each table in the

Re: [sqlalchemy] Documentation options

2019-03-21 Thread Rich Shepard
On Thu, 21 Mar 2019, Mike Bayer wrote: oh sure, I meant it uses up an enormous amount of memory / CPU to build the PDF. it looks terrible too because sphinx's templates aren't very good, plus SQLAlchemy's docs have a bunch of custom things going on that format even more badly. Mike, Okay.

Re: [sqlalchemy] Documentation options

2019-03-21 Thread Rich Shepard
On Thu, 21 Mar 2019, Mike Bayer wrote: not currently, however you can do a sphinx pdf build yourself if you feel like installing LaTeX, Mike, I write > 90% of my documents using LaTeX (with the LyX GUI front end). Sphinx is a new one for me so I'll go look at it. unfortunately SQLAlchemy's

[sqlalchemy] Documentation options

2019-03-21 Thread Rich Shepard
Are there PDF versions of the docs available for downloading and reading? I don't find an answer on the web site. TIA, Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and

Re: [sqlalchemy] Making Python3 list from set returned by SQL query

2019-03-11 Thread Rich Shepard
On Mon, 11 Mar 2019, Simon King wrote: Using your Industries class, a function to return that list of names could look like this: def get_industry_names(session): q = session.query(Industries) return [i.ind_name for i in q.all()] Does that do what you want? Simon, It probably will,

Re: [sqlalchemy] Making Python3 list from set returned by SQL query

2019-03-11 Thread Rich Shepard
I'm not sure exactly what you mean here. You can write a function that iterates over the rows and selects the attributes that you want. Simon, Let me try to be more clear. There's a database table named 'organizations', and an SA model class associated with it. One of the columns in the

[sqlalchemy] Making Python3 list from set returned by SQL query

2019-03-08 Thread Rich Shepard
Two classes in the model have columns with values constrained to specific text strings; one table has two such columns, another table has one. Because new strings might be added to the lists of allowed values for that column each has the acceptable values as rows in a table rather than in a

Re: [sqlalchemy] User name and password on local database

2019-03-05 Thread Rich Shepard
On Tue, 5 Mar 2019, Mike Bayer wrote: sure, if your PG database allows you to connect using "trust" or other localhost-style connection you can omit everything from the URL Thanks, Mike. Yes, I have all hosts on the LAN set to trust as nothing is exposed to the world. Best regards, Rich

[sqlalchemy] User name and password on local database

2019-03-05 Thread Rich Shepard
I'm writing an application for my business use; I'll be the only user and postgres is on the same server/workstation host. When I specify the engine using create_engine() can I leave off at least my password if not both it and my username? The database to which SA is connecting is owned by me.

Re: [sqlalchemy] Re: Organizing a project

2019-03-04 Thread Rich Shepard
On Mon, 4 Mar 2019, Jonathan Vanasco wrote: We "define" the model in a separate package - all the classes and relationships are in there. There are database support items as well, and some of the advanced/business logic that manipulate the ORM objects. By advanced-database-specific logic, an

Re: [sqlalchemy] Re: Organizing a project

2019-03-04 Thread Rich Shepard
On Sun, 3 Mar 2019, Jonathan Vanasco wrote: I generally write the SqlAlchemy models as a separate package, then import that into my MVC/etc patterned app. In terms of the SqlAlchemy logic, some of that I keep in the models package, others are in the core app. ... So my general advice is to

[sqlalchemy] Organizing a project

2019-03-03 Thread Rich Shepard
Starting my first SA project (have one more planned after this one's working) and appreciate advice on organizing project files. I understand the MVC pattern and am trying to apply it with subdirectories of model/, view/, and controller/ yet I'm unsure where to place SQLAlchemy. This is the

Re: [sqlalchemy] Expressing a SQL DOMAIN as a class

2019-01-16 Thread Rich Shepard
On Mon, 7 Jan 2019, Mike Bayer wrote: PG's ENUM does work that way, below the same type is shared: from sqlalchemy import Column from sqlalchemy import create_engine from sqlalchemy import Integer from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session from

Re: [sqlalchemy] Expressing a SQL DOMAIN as a class

2019-01-07 Thread Rich Shepard
On Mon, 7 Jan 201U9, Mike Bayer wrote: Postgresql has ENUM within CREATE TYPE: https://www.postgresql.org/docs/9.1/datatype-enum.html Mike, Thank you. I hadn't looked at the postgres docs for it. I'm not sure if this is a "DOMAIN" behind the scenes or what. Postgres supports the SQL

Re: [sqlalchemy] Expressing a SQL DOMAIN as a class

2019-01-07 Thread Rich Shepard
On Mon, 7 Jan 2019, Mike Bayer wrote: there's no built-in construct for CREATE DOMAIN but we do support reflection of custom domains, to do CREATE DOMAIN you can just use a DDL() construct: https://docs.sqlalchemy.org/en/latest/core/ddl.html?highlight=ddl, the DOMAIN you have there looks like

Re: [sqlalchemy] Expressing a SQL DOMAIN as a class

2019-01-07 Thread Rich Shepard
On Mon, 7 Jan 2019, Rich Shepard wrote: and in postgres tables is this attribute: state_code char(2), which is in the equivalent model classes; e.g., org_state = Column(String) Oops! This should also be state_code. Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational

[sqlalchemy] Expressing a SQL DOMAIN as a class

2019-01-07 Thread Rich Shepard
An application I'm developing (postgres back end) has a SQL DOMAIN as a check constraint on state/province codes. This is different from the SA ORM's domain perspective. The SQL statement is: CREATE DOMAIN the_state_code AS char(2) DEFAULT '??' CONSTRAINT valid_state_code CHECK (value IN ('AL',

Re: [sqlalchemy] Table CheckConstraint() limit?

2018-05-07 Thread Rich Shepard
On Mon, 7 May 2018, Mike Bayer wrote: the CHECK constraint only accepts a single SQL expression. Above, it looks like you re looking to add a CHECK constraint for each expression: __table_args__ = ( CheckConstraint(wtemp_unit.in_(['C', 'F'])), CheckConstraint(atemp_unit.in_(['C', 'F'])),

[sqlalchemy] Table CheckConstraint() limit?

2018-05-07 Thread Rich Shepard
The module, models.py, has five classes. Each has table constraints: three have a single table constraint, one has two table constraints, and one has seven table constraints. SA seems to reject more than four table constraints. With the last three commented out, there's no error:

Re: [sqlalchemy] Data type Float not recognized [FIXED]

2018-05-07 Thread Rich Shepard
On Mon, 7 May 2018, Rich Shepard wrote: What have I missed? Forgot to import that data type to the module. Mea culpa! Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete

[sqlalchemy] Data type Float not recognized

2018-05-07 Thread Rich Shepard
SQLAlchemy-1.2.7 installed here. Model column definition is: quant = Column(Float, nullable=False) yet Python3 tells me that Float is not defined: quant = Column(Float, nullable=False) NameError: name 'Float' is not defined If Float was a variable I created it would need to

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-07 Thread Rich Shepard
On Sun, 6 May 2018, Mike Bayer wrote: the second approach is probably more common, as it's more compact. Thanks, Mike. It works well here. Best regards, Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Rich Shepard
On Sun, 6 May 2018, Mike Bayer wrote: here is the correct way to construct and append the constraint: Thanks, Mike. I tried following the example from the docs and could not find what I missed. You provide two approaches. Is there a preference for one over the other, perhaps based on

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Rich Shepard
On Sun, 6 May 2018, Rich Shepard wrote: I'm missing how to properly use the above in my models.py module. Mike, And I have read the brief description of the CHECK Contstraint in the 'Defining Constraints and Indexes' section of the docs. Rich -- SQLAlchemy - The Python SQL Toolkit

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-06 Thread Rich Shepard
On Fri, 4 May 2018, Mike Bayer wrote: you're looking for a table-level check constraint with IN: table.append_constraint( CheckConstraint(table.c.data_type.in_('A', 'B', 'C')) ) Mike, I'm missing how to properly use the above in my models.py module. For example: class Sites(Base):

Re: [sqlalchemy] Column CheckConstraint() question

2018-05-04 Thread Rich Shepard
On Fri, 4 May 2018, Mike Bayer wrote: you're looking for a table-level check constraint with IN: Mike, Oh. I missed that since I write my postgres schema constraints on the column. alternatively, just use the backend-agnostic Enum type with native=False:

[sqlalchemy] Column CheckConstraint() question

2018-05-04 Thread Rich Shepard
In postgres (and I believe also in sqlite3) values in a table column can be restricted to certain values. In models.py the class Sites() includes this column: data_type = Column(String(12), nullable=False, CheckConstraint('Biogical', 'Chemical', 'Microbial', 'Physical',

[sqlalchemy] Integrating SQLAlchemy and wxPython4

2018-04-30 Thread Rich Shepard
I'm developing my first application using SQLAlchemy-1.2.7 and wxPython-4.0.1. I've found a 6-year-old blog post by Mike Driscoll illustrating a simple example. Are there other examples, tutorials, or open source applications from which I could learn? So far I have the database tables as

Re: [sqlalchemy] Two application versions, different back ends

2018-03-26 Thread Rich Shepard
On Mon, 26 Mar 2018, Jonathan Vanasco wrote: Pay close attention to which database functions you use, and how you use datetime fields. Those are two things were SQLite tends to differ from the other common databases. You can handle any of those differences using dialect specific custom

Re: [sqlalchemy] Two application versions, different back ends

2018-03-26 Thread Rich Shepard
On Mon, 26 Mar 2018, Mike Bayer wrote: this is a very open-ended question that can't be answered with a single document. SQLAlchemy will allow for standard SQL and DDL to work across both platforms transparently as well as differences in INSERT mechanics, and additionally transactional

[sqlalchemy] Two application versions, different back ends

2018-03-23 Thread Rich Shepard
I'm starting to write an application which will have two versions. One is single-user with sqlite3 as the backend, the other is multi-user with postgres as the backend. The single-user version will be written first. Both will be placed on github as F/OSS applications. Please point me to

[sqlalchemy] First application: visual linting requested

2018-01-15 Thread Rich Shepard
Several years ago I started a project with SQLAlchemy but dropped development to go in a different direction. Recently returning to the project I recognized my error and have returned to SQLAlchemy for this application (using version 1.2.1). I've read the ORM tutorial and followed links on

Re: [sqlalchemy] E901 TokenError: EOF in multi-line statement [SOLVED]

2015-07-25 Thread Rich Shepard
On Sat, 25 Jul 2015, Rich Shepard wrote: curr_value = = Column(Unicode(32), nullable = False) changed_by = = Column(Unicode(32), nullable = False) These were the problem. Rich

[sqlalchemy] E901 TokenError: EOF in multi-line statement

2015-07-25 Thread Rich Shepard
When running flake8 on the schema file the error, 'E901 TokenError: EOF in multi-line statement' is reported for the line following the last line of code at the end of the file. Web searches show that error means a missing quote (' or ), ')', ']', or '}'. There are no missing closures in the

[sqlalchemy] Syntax Checking

2015-07-24 Thread Rich Shepard
Because this is my first SQLAlchemy project and the schema file has 657 lines I would like to check for syntax errors before proceeding with the next step in application development. I find no index in the SA manual and cannot find the string 'syntax check' in the PDF file. Web search turns up

Re: [sqlalchemy] Syntax Checking

2015-07-24 Thread Rich Shepard
On Fri, 24 Jul 2015, Mike Bayer wrote: Python syntax or SQL syntax? Mike, The former. Typically in Python we rely on linters and runtime checks for this, same idea with SQL. Have not used a lint before with Python, but will run it on my SQLAlchemy code. I know that SQLite and

Re: [sqlalchemy] Syntax Checking

2015-07-24 Thread Rich Shepard
On Fri, 24 Jul 2015, Jonathan Vanasco wrote: In terms of linters, `flake8` (https://pypi.python.org/pypi/flake8) catches most mistakes I've made with SqlAlchemy. It's also useful to start writing Unit Tests that will interact with your SqlAlchemy models in predicted ways -- in addition to

Re: [sqlalchemy] Many-to-Many Table

2015-07-23 Thread Rich Shepard
On Thu, 23 Jul 2015, Mike Bayer wrote: conceptually not a big deal but API-wise has many mistakes. Sequences don't work with unicode, there is no value parameter, the table has no primary key. Mike, True, I don't want a sequence but the location ID, there needs to be a value column, and

[sqlalchemy] Many-to-Many Table

2015-07-23 Thread Rich Shepard
Originally posted here on June 4th, but no one responded. I'm now back on this project and this should be the last table I need to add to the schema. I would appreciate your review of the below class and whether it is good to go or needs your modifications. Section 2.1.15 in the 1.0.8 manual

Re: [sqlalchemy] best books on DB design for sqlalchemy users?

2015-07-23 Thread Rich Shepard
On Thu, 23 Jul 2015, Iain Duncan wrote: I feel like I should really take up my db game for an upcoming set of projects, and am wondering if there are any real standout books on db design that fit well with the design philosophy of SQLA. Recos much appreciated! Iain, Read Joe Celko's books,

[sqlalchemy] Many-to-Many Table

2015-06-04 Thread Rich Shepard
Section 2.1.15 in the 1.0.4 manual describes building an association table for many-to-many relationships. My application has a table that associates multiple locations with multiple types of data collected. That is, each location can have multiple types of data collected, and each data type

[sqlalchemy] Foreign Keys, Relationships, and Strings

2015-05-24 Thread Rich Shepard
I know it's a 3-day holiday for many of us in the US, but ... work needs to go on for us self-employed folks. :-) So, if I don't see a response until Tuesday, that's OK. In the SQLAlchemy docs I see that some strings are delineated with double quotes and some with single quotes. For example,

Re: [sqlalchemy] Foreign Keys, Relationships, and Strings

2015-05-24 Thread Rich Shepard
On Sun, 24 May 2015, Mike Bayer wrote: there is no reason for one or the other. Python allows both as is convenient and there's in fact no way to distinguish between string literals that were created with single or double quotes in any case. Mike, That's what I thought. That's why seeing

Re: [sqlalchemy] relationsip(): In Parent or Child Class?

2015-05-21 Thread Rich Shepard
On Thu, 21 May 2015, Mike Bayer wrote: I think the best use case is to put it on both, using back_populates. This is the focus of current documentation: http://docs.sqlalchemy.org/en/rel_1_0/orm/backref.html It's more verbose but I think it's clearer and functionally this is what backref does

[sqlalchemy] relationsip(): In Parent or Child Class?

2015-05-21 Thread Rich Shepard
There are a number of many-to-one table/class relationships in the application. In the many class I use ForeignKey() to relate that column to the appropriate 'one' class and column. Reading the ORM tutorial tells me that the relationship() function can be in either table. I can specify the

Re: [sqlalchemy] relationsip(): In Parent or Child Class?

2015-05-21 Thread Rich Shepard
On Thu, 21 May 2015, Mike Bayer wrote: I think the best use case is to put it on both, using back_populates. Validation check: am I correctly using relationship() in the following set of three tables? (N.B. Other columns removed for clarity and space saving.) class Agencies(Base):

Re: [sqlalchemy] Build With Different Backends [RESOLVED]

2015-05-19 Thread Rich Shepard
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tue, 19 May 2015, Mike Bayer wrote: Examples: date and time functions are entirely different on both platforms, schema migration operations e.g. ALTER are generally not supported on SQLite, SQLite has very different behavior regarding foreign

[sqlalchemy] Build With Different Backends

2015-05-19 Thread Rich Shepard
I thought there was a thread on this but I cannot find it so please point me to that thread if it exists. An application will be provided in two versions: a single-user version with SQLite3 as the backend, and a multi-user version with PostgreSQL as the backend. Am I correct that the only

Re: [sqlalchemy] foreign key relations

2014-08-03 Thread Rich Shepard
On Sun, 3 Aug 2014, nathan wrote: A player and a song are both created separately and associated with a client. class Client(Base): __tablename__ = 'client' id = Column(Integer, primary_key=True) class Player(Base): __tablename__ = 'player' id = Column(Integer, primary_key=True)

Re: [sqlalchemy] foreign key relations

2014-08-03 Thread Rich Shepard
On Sun, 3 Aug 2014, nathan wrote: Yes, you have it exactly right. There's currently 1 song to 1 player, but I'm thinking of going ahead and experimenting with assigning more than 1 song to a player. Nathan, It does not matter if you know the relationship(s) you want you can define them

[sqlalchemy] Foreign Keys and 'backref'

2014-07-31 Thread Rich Shepard
On page 23 of the 0.9.7 (Section 2.1.10, Building A Relationship) I see the example: class Address(Base): __tablename__ = 'addresses' id = Column(Integer, primary_key=True) email_address = Column(String, nullable=False) user_id = Column(Integer, ForeignKey('users.id')) user

Re: [sqlalchemy] Re: Foreign Keys and 'backref'

2014-07-31 Thread Rich Shepard
On Thu, 31 Jul 2014, Jonathan Vanasco wrote: backref indicates the string name of a property to be placed on the related mapper’s class that will handle this relationship in the other direction. The other property will be created automatically when the mappers are configured. Can also be passed

Re: [sqlalchemy] Re: Foreign Keys and 'backref'

2014-07-31 Thread Rich Shepard
On Thu, 31 Jul 2014, Jonathan Vanasco wrote: The relevant docs say this ( http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#sqlalchemy.orm.relationship.params.backref ) Re-reading this section of the docs I'm seeing what I missed the first time through. Thanks again, Jonathan,

Re: [sqlalchemy] Re: Foreign Keys and 'backref'

2014-07-31 Thread Rich Shepard
On Thu, 31 Jul 2014, Jonathan Vanasco wrote: yes. `backref` just lets you consolidate defining a relationship in a single place. `relationship` lets you specify the relationship from A to B `backref` is a kwarg to `relationship` that lets you specify the inverse ( B to A ) class

Re: [sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys

2014-07-30 Thread Rich Shepard
On Wed, 30 Jul 2014, Werner wrote: I don't like using 'name' columns as primary keys I would instead use an 'id' column and would set 'index=True' on the name column. Werner, The use of natural keys (such as a vehicle VIN, the US's SSN, or equipment serial number) is prefered over an

Re: [sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys

2014-07-30 Thread Rich Shepard
On Wed, 30 Jul 2014, Michael Bayer wrote: Celko's books are great but surrogate integer PKs are an unavoidable practice within relational databases, they are a requirement of most DBAs I've dealt with as they perform predictably in terms of indexing and space requirements, especially

Re: [sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys

2014-07-30 Thread Rich Shepard
On Wed, 30 Jul 2014, Michael Bayer wrote: With that, plus the predictable indexing, I'm always going to use them. But, I think there's a fair degree of preference still here. With natural PKs, the biggest issue is how much space indexes are going to take up considering that everything that FKs

Re: [sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys

2014-07-30 Thread Rich Shepard
On Wed, 30 Jul 2014, Michael Bayer wrote: Typically a UNIQUE constraint is placed on the natural key to prevent dupes. I can see this when the natural key is a single column, but wonder how a compound natural key is represented if a serial integer is used as the surrogate 'id' key. For

Re: [sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys

2014-07-30 Thread Rich Shepard
On Wed, 30 Jul 2014, Michael Bayer wrote: You make a single explicit UniqueConstraint object that specifies all three. Thanks, Mike. I missed that in the docs. Next question will appear only after a thorough search of your book. Rich -- You received this message because you are

[sqlalchemy] Single and Double Quotes

2014-07-30 Thread Rich Shepard
Is there a SQLAlchemy rule defining when single and double quotes are to be used? I see examples of both in a class, such as this example on page 103 of the 0.9.7 doc: class Entry(Base): __tablename__ = 'entry' entry_id = Column(Integer, primary_key=True) widget_id =

Re: [sqlalchemy] Single and Double Quotes

2014-07-30 Thread Rich Shepard
On Wed, 30 Jul 2014, Michael Bayer wrote: within python, single and double quotes are interchangeable and to the extent you see them used inconsistently is due to inconsistency on the part of myself and in some cases other developers who have written these docs. Mike, I thought that might

Re: [sqlalchemy] vacation...

2014-07-30 Thread Rich Shepard
On Wed, 30 Jul 2014, Michael Bayer wrote: I'm on vacation from thursday tomorrow through next thursday, so folks please hold down the fort! I won't be off the grid but I might not be able to get to my email as regularly. mike, Have fun, travel safely, and don't worry about all of us. Rich

[sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys

2014-07-29 Thread Rich Shepard
I'm starting to learn SQLAlchemy; have 0.9.7 installed on Slackware-14.1 with Python-2.7.5, wxPython-3.0.0.0, and postgresql-9.3.4. 1) In the docs I see a row constraint example using an integer comparison attrib.CheckConstraint('attrib5'). What is the syntax for a list, such as this

Re: [sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys [RESOLVED]

2014-07-29 Thread Rich Shepard
On Tue, 29 Jul 2014, Simon King wrote: Sorry, I don't know the answer to this, but based on the attrib example, I would guess that the string is passed directly to the database, so you would write something like: agency_name.CheckConstraint(agency_name IN ('Federal', 'State', 'County', 'City',

Re: [sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys

2014-07-29 Thread Rich Shepard
On Tue, 29 Jul 2014, Simon King wrote: Hope that helps, Simon, and others: As a check that I understand the basics please check the syntax of this set of three related tables: class Agencies(Base): __tablename__ = 'agencies' org_name = Column(String(48), primary_key = True)

Re: [sqlalchemy] Specifying a Row Check Constraint and Compound Primary Keys

2014-07-29 Thread Rich Shepard
On Tue, 29 Jul 2014, Rich Shepard wrote: CheckConstraint(org_lvl(org_lvl IN ('Federal', 'State', 'County', 'City', 'Local', 'Regional')) Oops! that first 'org_lvl(' comes out. Rich -- You received this message because you are subscribed to the Google Groups sqlalchemy group