#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    23
    Rep Power
    0

    Unhappy PostgreSQL macros?


    I have a select statement that looks like this:

    SELECT authorid, trim(lastname) || ', ' || trim(firstname) as authorname FROM authors ORDER BY authorname;

    but it's cumbersome. I would rather just do:

    SELECT authorid, authorname FROM authors ORDER BY authorname;

    but I don't want to maintain the authorname column in the database with a trigger that updates it any time lastname or firstname is changed. Does PostgreSQL have macros?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,777
    Rep Power
    348
    Create a VIEW: http://www.postgresql.org/docs/current/static/tutorial-views.html
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    23
    Rep Power
    0
    Thanks, this is exactly what I want.

IMN logo majestic logo threadwatch logo seochat tools logo