Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:29:24+00:00 2026-06-08T18:29:24+00:00

I am using an ORM (sqlalchemy) to fetch data from a PG database. I

  • 0

I am using an ORM (sqlalchemy) to fetch data from a PG database. I want to avoid specifying all the table column names in my hand crafted SQL statements*.

My assumption so far is that the returned columns are in the order of the DDL statements used to create the db tables. So far this is working – but I want to know if this is merely luck, or if it is specifically addressed in the (ANSI) SQL specification.

i.e. does ANSI SQL (and thus presumably the database) guarantee the order of columns returned in a SELECT * statement?

I am using PostgreSQL 8.4 as my backend db

  • yes, I am aware that using hand crafted SQL statements with an ORM defeats the purpose of an ORM, but needs must …
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:29:25+00:00Added an answer on June 8, 2026 at 6:29 pm

    Let’s consider the SQL standard, section 7.9 <query specification> as specified here:

    http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt

    <query specification> ::=
              SELECT [ <set quantifier> ] <select list> <table expression>
    [...]
    <select list> ::=
                <asterisk>
              | <select sublist> [ { <comma> <select sublist> }... ]
    
    [...]
    Syntax Rules
    1) Let T be the result of the <table expression>.
    3) Case:
           a) [...]
           b) Otherwise, the <select list> "*" is equivalent to a <value
              expression> sequence in which each <value expression> is a
              <column reference> that references a column of T and each
              column of T is referenced exactly once. The columns are ref-
              erenced in the ascending sequence of their ordinal position
              within T.
    

    So, in other words, yes, the SQL standard specifies that columns are to be projected according to their ordinal position within T. Note, that things get a bit tricky, when your <table expression> consists of several tables involving JOIN .. USING or NATURAL JOIN clauses. However, when selecting from a simple table, you’re probably fine assuming that the order is as expected.

    For completeness, the meaning of an ordinal position within T for tables is explained further down in 11.4 <column definition>:

    General Rules
         5) [...] The ordinal position included
            in the column descriptor is equal to the degree of T. [...]
    

    And then in 11.11 <add column definition> (for ALTER TABLE statements)

    General Rules
         4) [...] In particular, the degree of T
            is increased by 1 and the ordinal position of that column is
            equal to the new degree of T as specified in the General Rules
            of Subclause 11.4, "<column definition>".
    

    There are quite a few other SQL statements and clauses that depend on the formal specification of ordinal positions within <table expressions>. Some examples:

    13.8 <insert statement> 
         (when omitting the `<insert column list>`)
    20.2 <direct select statement: multiple rows>
         (when `<sort specification>` contains an `<unsigned integer>`)
    

    Postgres, in particular, is quite standards-compliant, so if you really want to SELECT *, go ahead!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create a table in database using sqlalchemy and now want to make a
I'm using Coldfusion ORM (Hibernate), and have a cfc mapped to a database table.
I am using cfwheels (coldfusion orm framework). I recently moved some data from my
Using the SQLAlchemy ORM, I want to make sure values are the right type
I am using a relational database via SQLAlchemy. I want to spawn a job
I access a a postgres table using SQLAlchemy. I want a query to have
I am using SqlAlchemy, a python ORM library. And I used to access database
I'm writing an ORM using Elixir and SQLAlchemy to handle moving spreadsheet-like data into
i am using kohana ORM in order to get some results from the database.
I'm going to have two independent programs (using SqlAlchemy / ORM / Declarative) that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.