Unix Technical Forum

CASTING in JOIN or WHERE

This is a discussion on CASTING in JOIN or WHERE within the pgsql Novice forums, part of the PostgreSQL category; --> Hi All, I have written some SQL and have noticed that PostgreSQL seems to be modifying the syntax slightly. ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 08:30 PM
Keith Worthington
 
Posts: n/a
Default CASTING in JOIN or WHERE

Hi All,

I have written some SQL and have noticed that PostgreSQL seems to be modifying
the syntax slightly. I do not care per se but if it impacts performance I
want to understand how to write the SQL in the more efficient form. I am
recalling posts commenting on columns with dissimilar types and the lack of
index usage.

I have a column of type varchar
id | character varying(20) | not null

I use this in a WHERE clause
WHERE id = 'SN'
PostgreSQL changes the statement to
WHERE id::text = 'SN'::text

I notice a similar behavior when doing JOINs
Given in table 1
item_id | character varying(20) | not null
and in table 2
id | character varying(20) | not null

The JOIN
ON ( tbl_line_item.item_id = tbl_item.id )
is changed to
ON ( tbl_line_item.item_id::text = tbl_item.id::text )

Kind Regards,
Keith

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:30 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com